Converti JSON in CSV

Convertire JSON in CSV

Aspose.Cells per Python via .NET supporta la conversione di JSON semplici e annidati in CSV. A tale scopo, l’API fornisce le classi JsonLayoutOptions e JsonUtility. La classe JsonLayoutOptions fornisce le opzioni per il layout JSON come ignore_array_title (ignora il titolo se l’array è una proprietà di un oggetto) o array_as_table (elabora l’array come una tabella). La classe JsonUtility elabora il JSON utilizzando le opzioni di layout impostate con la classe JsonLayoutOptions.

Il seguente esempio di codice dimostra l’uso delle classi JsonLayoutOptions e JsonUtility per caricare il file JSON di origine e genera il file CSV di output.

Codice di Esempio

from aspose.cells import Workbook
from aspose.cells.utility import JsonLayoutOptions, JsonUtility
# For complete examples and data files, please go to https:# github.com/aspose-cells/Aspose.Cells-for-.NET
# Source directory
sourceDir = RunExamples.Get_SourceDirectory()
# Output directory
outputDir = RunExamples.Get_OutputDirectory()
# Read JSON file
str = open(sourceDir + "SampleJson.json", "r").read()
# Create empty workbook
workbook = Workbook()
# Get Cells
cells = workbook.worksheets[0].cells
# Set JsonLayoutOptions
importOptions = JsonLayoutOptions()
importOptions.convert_numeric_or_date = True
importOptions.array_as_table = True
importOptions.ignore_array_title = True
importOptions.ignore_object_title = True
JsonUtility.import_data(str, cells, 0, 0, importOptions)
# Save Workbook
workbook.save(outputDir + str(r"SampleJson_out.csv"))