I have 10,000's of json objects in a json file in following format :
{ "a": 1,
"b" : 2,
"c" : {
"d":3
}
}{ "e" : 4,
"f" : 5,
"g" : {
"h":6
}
}
How can I load these as a json object?
Two methods that I've tried with corresponding error :
Method 1 :
>>> with open('test1.json') as jsonfile:
... for line in jsonfile:
... data = json.loads(line)
...
Error :
Traceback (most recent call last):
File "<stdin>", line 3, in <module>
File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.5/json/decoder.py", line 339, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python3.5/json/decoder.py", line 355, in raw_decode
obj, end = self.scan_once(s, idx)
json.decoder.JSONDecodeError: Expecting property name enclosed in double quotes: line 2 column 1 (char 10)
Method 2 :
>>> with open('test1.json') as jsonfile:
... data = json.load(jsonfile)
...
Error :
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
File "/usr/lib/python3.5/json/__init__.py", line 268, in load
parse_constant=parse_constant, object_pairs_hook=object_pairs_hook, **kw)
File "/usr/lib/python3.5/json/__init__.py", line 319, in loads
return _default_decoder.decode(s)
File "/usr/lib/python3.5/json/decoder.py", line 342, in decode
raise JSONDecodeError("Extra data", s, end)
json.decoder.JSONDecodeError: Extra data: line 7 column 1 (char 46)
>>>
I've read the related questions but none of them helped.
json.loaderror.