I am having trouble parsing the resulting json data to return only wanted section (e.g., 'name, 'aisle', 'status'). How can I modify the output to only print those items?
Code:
for coro in tqdm(asyncio.as_completed(tasks, loop=loop)):
try:
response = await coro
if response is None:
continue
data, store = response
result = json.loads(data['searchResults'])['results'][0]
summary = {
'name': result['name'],
'aisle': result['price']['aisle'][0],
'status': result['inventory']['status'],
}
results[store] = summary
except (IndexError, KeyError):
continue
with open('Testing.txt', 'w') as outfile:
json.dump(results, outfile, indent = 2)
outfile.write('\n')
When I print I get the following format:
{
"1": {
"name": "camera",
"aisle": "M.3",
"status": "In Stock"
},
"2": {
"name": "camera",
"aisle": "M.53",
"status": "Out of Stock"
},
"3":{
"name": "camera",
"aisle": "M.32",
"status": "In Stock"
}
}
I would like the output for each loop on a single line, such as:
'35': { 'name': 'Camera', 'aisle': 'M.35', 'status': 'Out of stock' },
'36': { 'name': 'Camera', 'aisle': 'J.35', 'status': 'In stock' }