I have created my own json data with an array I would like to parse into a python list. However, I've been having trouble doing so.
How can I extract my json array into a python list?
json data:
[
{
"ip": "192.168.241.109",
"cameras":
{
"front": "nf091",
"inside": "nf067",
"right": "004317",
"rear": "000189",
"left": "nf084"
}
},
{
"ip": "192.168.241.110",
"cameras":
{
"front": "nf091",
"inside": "nf067",
"right": "004317",
"rear": "000189",
"left": "nf084"
}
}
]
My json data is valid, so I don't know why I'm having trouble with the below code:
system_json = open(json_file)
json_obj = json.load(system_json)
camera_details = [[i['front'], i['rear'], i['left'], i['right'], i['inside']] for i in json_obj['cameras']]
The above code snippet does not work as it yields the list indices must be integers, not str error.
What am I doing wrong, and how can I properly parse my json array into a python list?