I have the JSON file below and i am trying to extract the value dob_year from each item if the name element is jim.
This is my try:
import json
with open('j.json') as json_file:
data = json.load(json_file)
if data['name'] == 'jim'
print(data['dob_year'])
Error:
File "extractjson.py", line 6 if data['name'] == 'jim' ^ SyntaxError: invalid syntax
this is my file.
[
{
"name": "jim",
"age": "10",
"sex": "male",
"dob_year": "2007",
"ssn": "123-23-1234"
},
{
"name": "jill",
"age": "6",
"sex": "female",
"dob_year": "2011",
"ssn": "123-23-1235"
}
]
(d['dob_year'] for d in data if d['name'] == 'jim')