Load pretty printed JSON from file into python? -


i have large json document stored in pretty-print format file, file looks like:

$ nano data.json  { "type" : "object", "properties" : {   "price" : {"type" : "number"},   "name" : {"type" : "string"},   }, } 

the traditional ways i've found reading such json files, such as...

with open('data.json', 'r') handle:     data = json.load(handle) 

and...

json_data=open('data.json','r') data = json.load(json_data) json_data.close() 

and...

data = [] open('data.json') f:     line in f:         data.append(json.loads(line)) 

and...

ss = '' open('data.json', 'r') f:     line in f:         ss += ''.join(line.strip())  data = json.loads(ss.decode("utf-8","replace")) 

...seem work single-string, not pretty-print formatted json.

how load json of format file? errors keep getting when trying these formats are...

traceback (most recent call last):   file "<stdin>", line 7, in <module>   file "/usr/lib/python2.7/json/__init__.py", line 326, in loads     return _default_decoder.decode(s)   file "/usr/lib/python2.7/json/decoder.py", line 366, in decode     obj, end = self.raw_decode(s, idx=_w(s, 0).end())   file "/usr/lib/python2.7/json/decoder.py", line 382, in raw_decode     obj, end = self.scan_once(s, idx) valueerror: expecting , delimiter: line 1 column 250 (char 250)  valueerror: expecting , delimiter: line 9 column 13 (char 310) 

for else finding in future googling things similar did when posted this---you may think error in loading, mine above in json itself, rather loading (as martijn pieters pointed out). copying schema jsonschema python project---but this, turned out, not json, deceptively similar-looking python dictionary.


Comments

Popular posts from this blog

How to mention the localhost in android -

php - Calling a template part from a post -