Learn how to convert JSON data or files to CSV format using Python: https://blog.aspose.com/2021/09/04/convert-json-data-to-csv-using-python/
Convert JSON to CSV in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// load JSON data | |
jsonInput = '[{"nodeId":1,"reputation":1134},{"nodeId":2,"reputation":547},{"nodeId":3,"reputation":1703},{"nodeId":4,"reputation":-199},{"nodeId":5,"reputation":-306},{"nodeId":6,"reputation":-49},{"nodeId":7,"reputation":1527},{"nodeId":8,"reputation":1223}]' | |
# create a blank Workbook object | |
workbook = Workbook() | |
# access default empty worksheet | |
worksheet = workbook.getWorksheets().get(0) | |
# set JsonLayoutOptions for formatting | |
layoutOptions = JsonLayoutOptions() | |
layoutOptions.setArrayAsTable(True) | |
# import JSON data to CSV | |
JsonUtility.importData(jsonInput, worksheet.getCells(), 0, 0, layoutOptions) | |
# save CSV file | |
workbook.save("output.csv", SaveFormat.CSV) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment