I've written a JSON object (generated by someone else, in code I have no access to) to a file named kommscache.json
, and now I'm trying to read it in again in Python.
This is what I do:
import json
from pprint import pprint
with open('kommscache.json') as data_file:
data = json.load(data_file)
pprint(data)
On the call to json.load()
, I get the following error message:
Traceback (most recent call last):
File "./kladd.py", line 7, in <module>
data = json.load(data_file)
File "/usr/lib/python2.7/json/__init__.py", line 280, in load
**kw)
File "/usr/lib/python2.7/json/__init__.py", line 328, in loads
return _default_decoder.decode(s)
File "/usr/lib/python2.7/json/decoder.py", line 365, in decode
obj, end = self.raw_decode(s, idx=_w(s, 0).end())
File "/usr/lib/python2.7/json/decoder.py", line 381, in raw_decode
obj, end = self.scan_once(s, idx)
ValueError: Expecting property name: line 1 column 1 (char 1)
The first few lines of the JSON file look like this (I've tried a non-prettyprinted version too, with the same result):
{u'filtered': 458,
u'items': [{u'comment_count': 0,
u'current_revision': {u'created_by': {u'avatar': 19435601,
Unfortunately, I can't show you the entire file because it contains some sensitive data (and it's over 6000 lines long...), but if I'm reading the error message correctly the error is already at the start of the file. However, I can't see why this JSON syntax isn't correct. I've double-checked, and all the braces and brackets in this snippet have matching closing ones.
Why can't I load this JSON object?