0

I have a json file that looks like this exactly:

{'data':[-99,19,1212,121,2131,323321,123]}

saved as list.json

and I have a python script that needs the list [-99,19,1212,121,2131,323321,123]

 import json

 with open ("list.json", "r") as myfile:
        data=myfile.read().replace('\n', '')
 spots1 = json.loads(data) #<-- Error
 spots = spots1['data']

Error:

File "pythonscript.py", line 479, in <module>
    spots1 = json.loads(data)
  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)

I can't figure out what is wrong with my formatting. Any help would be greatly appreciated!

Martijn Pieters
  • 1,048,767
  • 296
  • 4,058
  • 3,343
aishpr
  • 143
  • 3
  • 15

1 Answers1

0

Python wants you to use "(double quote) for properties names in a json dictionary and not '(Single Quote)

Try this String: {"data":[-99,19,1212,121,2131,323321,123]}

See this question for more details: python: single vs double quotes in JSON

Community
  • 1
  • 1
Jon
  • 333
  • 1
  • 6