![]() ![]() The fieldnames for the writer are set to the keys of the first element of the data. Then, it creates a new CSV file and uses the CSV module’s DictWriter() class to write the data to the file. In this example, the code first opens the JSON file using the open() function and the JSON module’s load() function, which reads the file’s contents and converts it to a Python object. # Create a new CSV file and write the data with open( 'data.csv', 'w', newline = '') as csv_file: Import csv import json # Open the JSON file with open( 'data.json') as json_file:
0 Comments
Leave a Reply. |