Dynamically Reading JSON Data

{
"supplier": {
"supp_name": "",
"supp_id": "",
"address": {
"addressLine1": "",
"Addressline2": "",
"Postcode": ""

},
"Billing_address": {
"addressLine1": "",
"Addressline2": "",
"AddressLine3": ""

},
"CurrencyCode": "",
"CountryCode": ""
}
}


import json
f=open("supplier.json")
data=f.read()
jd=json.loads(data)
tn=list(jd.keys())[0]
for k,v in jd[tn].items():
    if len(v)==0:
        print(k)
    else:
        print(k)
        for x,y in v.items():
            print(" ",x)
           

Comments

Popular posts from this blog

Converting Excel File to JSON File using xlrd module

Using Oracle with Python

Using time module