简体   繁体   中英

Read JSON file using PYTHON and create an excel file with that data

I am working on a project where i have to read a JSON file and then load the data in an excel file. Not sure how to go about this in Python and i need some real help. Here is the JSON structure:

{"Models":[{"name":"AAA", "text":"some text", "structure":[{"column":"zzz", "type":"string"}, .....]}, {"name":"BBB", "text":"some text", "structure":[{"column":"zzz", "type":"string"}, .....]}]}

I need to convert this in the following excel format: Name| Column | Type AAA | zzz | string BBB | yyy | text CCC | xxx | string

Not sure how to do this as Column and Type are under a different key and Name is different key.

Load json file as dict and iterate through it

import json

f = open("f.json")
data = json.load(f)
f.close()
for x in data.get('Models'):
    name = x.get('name')
    for s in x.get('structure'):
        #write this string to a csv file
        print(name + ' ' + s.get('column') + ' ' + s.get('type'))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM