Optionaloptions: { env?: string; host?: string; token?: string }Convert data between different formats (JSON, CSV, Excel)
Supports structured data when converting from JSON format with:
header, items, and footer propertiesLibrary reference UUID
Raw data to convert
Conversion parameters including structured data options
Promise resolving to converted data
// Convert JSON to CSV
const jsonData = [
{ name: "John Doe", age: 30, email: "john@example.com" },
{ name: "Jane Smith", age: 25, email: "jane@example.com" }
];
const csvResult = await dms.convertData(libraryRef, jsonData, {
from: 'json',
to: 'csv'
});
console.log(csvResult.data); // CSV string
// Convert structured JSON with header as comments
const structuredData = {
header: {
content: {
report_title: "Monthly Sales Report",
generated_by: "Sales System"
}
},
items: [
{ product: "Widget A", sales: 100 },
{ product: "Widget B", sales: 150 }
],
footer: {
content: {
total_sales: 250
}
}
};
const csvWithComments = await dms.convertData(libraryRef, structuredData, {
from: 'json',
to: 'csv',
header_as_comment: true,
separator_rows: 2
});
// Convert JSON to Excel with custom sheet name
const excelResult = await dms.convertData(libraryRef, jsonData, {
from: 'json',
to: 'excel',
sheet_name: 'Customer Data'
});
// excelResult.data is a Blob
Convert CSV data to Excel (.xlsx) format
Library reference UUID
CSV data string (with headers in first row)
Optionaloptions: ConversionOptionsOptional conversion options
Promise resolving to Excel file as Blob
const csvString = `name,age,email
John Doe,30,john@example.com
Jane Smith,25,jane@example.com`;
const excelResponse = await dms.csvToExcel(libraryRef, csvString, {
sheet_name: 'Imported Data'
});
// Handle the Excel blob
const blob = excelResponse.data;
const url = URL.createObjectURL(blob);
// Use url for download or further processing
Convert CSV data to JSON format
Library reference UUID
CSV data string (with headers in first row)
Promise resolving to JSON array
const csvString = `name,age,email
John Doe,30,john@example.com
Jane Smith,25,jane@example.com`;
const jsonResponse = await dms.csvToJson(libraryRef, csvString);
console.log(jsonResponse.data);
// Output:
// [
// { name: "John Doe", age: "30", email: "john@example.com" },
// { name: "Jane Smith", age: "25", email: "jane@example.com" }
// ]
Convert Excel (.xlsx) data to CSV format
Library reference UUID
Excel file data as Blob or ArrayBuffer
Optionaloptions: ConversionOptionsOptional conversion options
Promise resolving to CSV string
// From file input
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0]; // Excel file
const csvResponse = await dms.excelToCsv(libraryRef, file, {
sheet_name: 'Data' // optional, defaults to first sheet
});
console.log(csvResponse.data);
// Output: CSV string with data from Excel sheet
// Save as CSV file
const csvBlob = new Blob([csvResponse.data], { type: 'text/csv' });
const url = URL.createObjectURL(csvBlob);
const link = document.createElement('a');
link.href = url;
link.download = 'converted.csv';
link.click();
Convert Excel (.xlsx) data to JSON format
Library reference UUID
Excel file data as Blob or ArrayBuffer
Optionaloptions: ConversionOptionsOptional conversion options
Promise resolving to JSON array
// From file input
const fileInput = document.querySelector('input[type="file"]');
const file = fileInput.files[0]; // Excel file
const jsonResponse = await dms.excelToJson(libraryRef, file, {
sheet_name: 'Sheet1' // optional, defaults to first sheet
});
console.log(jsonResponse.data);
// Output: JSON array with data from Excel sheet
// From ArrayBuffer
const arrayBuffer = await file.arrayBuffer();
const jsonFromBuffer = await dms.excelToJson(libraryRef, arrayBuffer);
Get information about data format and structure
Library reference UUID
Raw data to analyze
Analysis parameters
Promise resolving to data information
const jsonData = [
{ name: "John", age: 30, email: "john@example.com" },
{ name: "Jane", age: 25, email: "jane@example.com" }
];
const dataInfo = await dms.getDataInfo(libraryRef, jsonData, {
format: 'json'
});
console.log(dataInfo.data);
// Output:
// {
// format: "json",
// size_bytes: 245,
// record_count: 2,
// field_count: 3,
// fields: ["name", "age", "email"],
// library_ref: "98bee1cb-0f21-4582-a832-7c32b4b61831"
// }
Convert JSON data to CSV format
This method supports both regular JSON arrays and structured data with auto-detection:
Library reference UUID
JSON data (array of objects or structured data)
Promise resolving to CSV string
// Regular JSON to CSV
const jsonData = [
{ name: "John Doe", age: 30, email: "john@example.com" },
{ name: "Jane Smith", age: 25, email: "jane@example.com" }
];
const csvResponse = await dms.jsonToCsv(libraryRef, jsonData);
console.log(csvResponse.data);
// Output:
// name,age,email
// John Doe,30,john@example.com
// Jane Smith,25,jane@example.com
// Structured JSON with auto-detection
const structuredData = [
{ metadata: "EMPLOYEE REPORT\nGenerated: 2025-10-08" },
{ name: "John Doe", age: 30, position: "Developer" },
{ name: "Jane Smith", age: 25, position: "Designer" },
{ name: "Total Employees:", age: null, position: "2 people" }
];
const structuredCsv = await dms.jsonToCsv(libraryRef, structuredData);
// Auto-detects header, items, and footer sections
Convert JSON data to Excel (.xlsx) format
Supports both regular JSON arrays and structured data patterns. Excel files are always generated with .xlsx extension.
Library reference UUID
JSON data (array of objects or structured data)
Optionaloptions: ConversionOptionsOptional conversion options
Promise resolving to Excel file as Blob
// Regular JSON to Excel
const jsonData = [
{ name: "John Doe", age: 30, email: "john@example.com" },
{ name: "Jane Smith", age: 25, email: "jane@example.com" }
];
// Basic conversion
const excelResponse = await dms.jsonToExcel(libraryRef, jsonData);
const blob = excelResponse.data; // Blob for download
// With custom sheet name
const excelWithOptions = await dms.jsonToExcel(libraryRef, jsonData, {
sheet_name: 'Customer Data'
});
// Structured data with explicit sections
const structuredData = {
header: { content: { title: "Monthly Report" } },
items: [{ product: "Widget A", sales: 100 }],
footer: { content: { total_sales: 100 } }
};
const structuredExcel = await dms.jsonToExcel(libraryRef, structuredData);
// Create download link
const url = URL.createObjectURL(structuredExcel.data);
const link = document.createElement('a');
link.href = url;
link.download = 'report.xlsx'; // Always .xlsx extension
link.click();
Optionalparams: anyOptionalparams: anyValidate data format without performing conversion
Library reference UUID
Raw data to validate
Validation parameters
Promise resolving to validation result
const jsonData = [{ name: "John", age: 30 }];
const validation = await dms.validateData(libraryRef, jsonData, {
format: 'json'
});
console.log(validation.data);
// Output:
// {
// valid: true,
// message: "Data is valid JSON format",
// library_ref: "98bee1cb-0f21-4582-a832-7c32b4b61831"
// }
// Handle invalid data
try {
const invalidValidation = await dms.validateData(libraryRef, "invalid json", {
format: 'json'
});
} catch (error) {
console.error('Validation failed:', error.response?.data?.message);
}
Document Management System (DMS) API client
Provides comprehensive document and media management capabilities including:
Data Conversion Features
The DMS class includes powerful data conversion capabilities that allow you to:
Supported Formats
Structured Data Support
When converting from JSON, the API supports:
Explicit Structure: JSON with dedicated sections
Auto-Detection: Mixed arrays with metadata and summary objects
Error Handling
All conversion methods may throw errors with code 3003 for conversion failures. Always wrap calls in try-catch blocks for production use.
Example