Surgically Extracting Datum From Nested Json Object Using Python
From this nested JSON object I need to parse out and pretty print the value for 'id' and the value for 'location'. { 'links': { 'self': 'http://localhost:2
Solution 1:
I'm taking a leap and guessing the info you really want in the end, which is a list of item IDs for each location ID:
import json
from collections import defaultdict
with open('prettyPrint.txt') as data_file:
data = json.load(data_file)
locations = defaultdict(int)
for item in data['data']:
location = item['relationships']['location']['data']['id']
locations[location] += 1
print(locations)
Post a Comment for "Surgically Extracting Datum From Nested Json Object Using Python"