Home > Back-end >  Read Data in a nested Json
Read Data in a nested Json

Time:12-13

I have this very long json here: https://textup.fr/601885q4 and would like to read a data that is in one of the "payment_token_contract" specifically those with "id":1 My problem is that I dont get how to call the specific dictionnary as they all have the same name. Is this even possible, i'm not used to manipulating such complex objects as i'm a beginner. I would have tried something like : ["orders][x]["id":1]["base_price"] with x being in a for loop that iterates through each "orders" present. But I cant manage to put it all together. Thanks for your help !

CodePudding user response:

You can use a for loop to iterate over the orders, you can check the value of the payment contract id and if its 1 then print the base price for that order

import json

jdata = "yourjson"
jdict = json.loads(jdata)

for order in jdict["orders"]:
    if order['payment_token_contract']['id'] == 1:
        print(order["base_price"])

I have omited the json data as its to long but you can image jdata is the string of your json

OUTPUT

149000000000000000000
  • Related