I'm having trouble parsing multiple objects within a JSON array. I can get my code to work, but I have to manipulate the JSON file which I shouldn't have to do.
I'm on Python 3, and here's my code:
If I delete the square brackets (array), delete the commas, insert hard returns after each line the data comes back correct. Here's how I reformat the JSON:
I'm on Python 3, and here's my code:
import json tradingList = [] print with open('party.json') as f: for jsonObj in f: tradingDict = json.loads(jsonObj) tradingList.append(tradingDict) print for trade in tradingList: print(trade["id"], trade["name"])Here's my original JSON data:
Output:[{"id":3090,"name":"Wegmans","aventionId": null},
{"id":1156,"name":"Giant","aventionId": null},
{"id":4340,"name":"Safeway","aventionId": null},
{"id":5965,"name":"Publix","aventionId":[]}]
That results in an error "list indices ust be integers or slices, not str".If I delete the square brackets (array), delete the commas, insert hard returns after each line the data comes back correct. Here's how I reformat the JSON:
Output:{"id":3090,"name":"Wegmans","aventionId": null}
{"id":1156,"name":"Giant","aventionId": null}
{"id":4340,"name":"Safeway","aventionId": null}
{"id":5965,"name":"Publix","aventionId":[]}
Here's the desired output:Output:3090 Wegmans
1156 Giant
4340 Safeway
5965 Publix
Any help is appreciate, thank you!