![]() ![]() Create the following function:- def create_list_from_json(jsonfile): with open(jsonfile) as f: data = json.load(f) data_list = # create an empty list # append the items to the list in the same order. We must note that few of these columns are the keys of second level dictionaries as shown in the pic above. Now, for each json file we will extract the data of the relevant columns e.g. We will be using os module to browse through the directories.įirst of all, we will skim through the directory ‘descriptions’ and add all the files (filenames) into a list:- import os import json import csv def get_list_of_json_files(): list_of_files = os.listdir('descriptions') return list_of_files We will be making it a re-useable script and hence, we will not be doing any hard coding for it. ![]() ![]() So create an empty ‘output.csv’ file and copy paste the above line as the header in it:- $ nano output.csv We need to parse the following columns from the json file and convert it to csv file:. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |