Reputation: 109
I'm trying to parse a JSON file with multiple objects by one of the values in the object, however I am not sure if this is possible with my method.
JSON
[{"Temp":512,"Name":"sdfd3","SearchTags":["North"]},
[{"Temp":45,"Name":"dfs5","SearchTags":["South"]},
[{"Temp":251,"Name":"sfsd6","SearchTags":["North"]},
Python
myObj = response.content;
x = json.loads(myObj)
for item in x:
if myObj(Name) == "dfs5":
print(Temp, SearchTags)
I am new to JSON and Python but cannot seem to find any guidance on searching where a JSON file has multiple lines.
Any help is greatly appreciated.
Upvotes: 0
Views: 265
Reputation: 716
First of all your JSON object is not correct. Still, I have tried to recreate your issue.
myObj = [
{"Temp":"512","Name":"sdfd3","SearchTags":["North"]},
{"Temp":45,"Name":"dfs5","SearchTags":["South"]},
{"Temp":251,"Name":"sfsd6","SearchTags":["North"]}
]
for item in myObj:
if item.get("Name") == "dfs5":
print(item["Temp"], item["SearchTags"])
Upvotes: 1