Question: I'm trying to parse data from a JSON file, but cannot figure out how to print every instance of dish from the file. I realizd
I'm trying to parse data from a JSON file, but cannot figure out how to print every instance of "dish" from the file. I realizd that if I print statements like this, I can access the "dish" value I need.
There is a pretty obvious pattern here, so I wonder, is there a for loopI can use to iterate through the JSON and return these every instance of 'dish' more efficiently? Or some other way?
print json['menu'][0]['dish'] #prints pizza
print json['menu'][0]['menu'][0]['dish'] #prints sushi
print json['menu'][0]['menu'][0]['menu'][0]['dish'] #prints tacos
print json['menu'][0]['menu'][1]['dish'] #prints cereal
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
