Subsetting a JSON

Let's have a look at a new JSON file:

 with open('product.json') as json_string: 
d=json.load(json_string)
d

We get the following output:

Loading a JSON file with several degrees of nesting

This is a JSON with several degrees of nesting. The hits key contains a JSON as a value whose key value is hits. The value of this JSON is a list containing another JSON.

Let's say that we want to find out the score value from this JSON:

 d['hits']['hits'][0]['_score'] 

Similarly, the image URL can be found as follows:

 d['hits']['hits'][0]['_source']['r']['wayfair']['image_url']
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset