Taewan
Taewan

Reputation: 1227

Convert Json into Dictionary in Python

Following Json is from Mongodb by querying collection.find() method. How do I convert this Json into Dictionary in Python? I want to map BMW as key and Series 3 as value in my dictionary.

Python:

content = list(collection.find({"_id": "sample_abc"}, {"Car":1, "_id":0}))
print (content)

Console:

[{'Car': [{'BMW': 'series 3'}, {'Audi': 'A4'}]}]

Upvotes: 0

Views: 114

Answers (2)

methane
methane

Reputation: 479

content[0]['Car'][0] may be {'BMW': 'series 3'}

Upvotes: 1

Ryan
Ryan

Reputation: 3709

This will do it:

import json
q = json.loads(content)

Upvotes: 4

Related Questions