8/24/2023 0 Comments Python code to convert json to csv![]() The desired CSV data is created using the generate_csv_data() function.If the value is again a dict then it concatenates the key string with the key string of the nested dict. It checks for the key-value pairs in the dict object. We normalize the dict object using the normalize_json() function. import csv import json import glob import os for filename in glob.glob ('//path/to/file/.csv'): csvfile os.path.splitext (filename) 0 jsonfile csvfile + '.json' with open (csvfile+'.csv') as f: reader csv.DictReader (f) rows list (reader) with open (jsonfile, 'w') as f: json. ![]() The read_json() function is used for the task, which taken the file path along with the extension as a parameter and returns the contents of the JSON file as a python dict object. This will help us to make use of python dict methods to perform some operations.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |