Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.
Aspose.Cells supports converting simple as well as nested JSON to CSV. For this, the API provides JsonLayoutOptions and JsonUtility classes. The JsonLayoutOptions class provides the options for JSON layout like JsonLayoutOptions.getArrayAsTable() (processes the array as a table). The JsonUtility class processes the JSON using the layout options set with the JsonLayoutOptions class.
The following code sample demonstrates the use of JsonLayoutOptions and JsonUtility classes to load the source JSON file and generate the output CSV file.
const fs = require("fs");
const path = require("path");
const AsposeCells = require("aspose.cells.node");
// Source directory
const sourceDir = path.join(__dirname, "data");
// Output directory
const outputDir = path.join(__dirname, "output");
// Create sample JSON if missing
const jsonPath = path.join(sourceDir, "SampleJson.json");
// Read JSON file
const str = fs.readFileSync(jsonPath, "utf-8");
// Create empty workbook
const workbook = new AsposeCells.Workbook();
// Get Cells
const cells = workbook.getWorksheets().get(0).getCells();
// Set JsonLayoutOptions
const importOptions = new AsposeCells.JsonLayoutOptions();
importOptions.setConvertNumericOrDate(true);
importOptions.setArrayAsTable(true);
importOptions.setIgnoreTitle(true);
AsposeCells.JsonUtility.importData(str, cells, 0, 0, importOptions);
// Save Workbook
workbook.save(outputDir + "SampleJson_out.csv");
Analyzing your prompt, please hold on...
An error occurred while retrieving the results. Please refresh the page and try again.