I have this JSON file:
[
{
id: "29",
name: "abc",
email: "[email protected]",
data: "2016-05-03"
},
{
id: "17",
name: "ghi",
email: "[email protected]",
data: "2016-05-12"
},
{
id: "12",
name: "qwe",
email: "[email protected]",
data: "2016-04-11"
}
]
I wrote this script:
with open('C:/Users/L30607/Desktop/FYP/FourthMay-AllStudents-stackoverflow.json') as json_data:
d = json.load(json_data)
json_data.close()
pprint(d)
How do I parse the file and extract the array?
I want to get:
d = [{id: "29",name: "abc",email: "[email protected]",data: "2016-05-03"},{id: "17",name: "ghi",email: "[email protected]",data: "2016-05-12"},{id: "12",name: "qwe",email: "[email protected]",data: "2016-04-11"}]
json_data.close()when you are already inside thewithblock, as it already closes the file for you at the block ending.