Sebastian D.
Sebastian D.

Reputation: 29

decoding json string with json.loads in python

I have string like that:

jstring = {"label":"2017-06-01","value1":"250.730000"},{"label":"2017-06-02","value1":"250.730000"}

end if I use json.loads(jstring) I got this error:

Traceback (most recent call last):
  File "Funds.py", line 44, in <module>
    data  = json.loads(array)
  File "/usr/lib/python2.7/json/__init__.py", line 339, in loads
    return _default_decoder.decode(s)
  File "/usr/lib/python2.7/json/decoder.py", line 367, in decode
    raise ValueError(errmsg("Extra data", s, end, len(s)))
ValueError: Extra data: line 1 column 45 - line 1 column 54951 (char 44 - 54950)

What should I do with it?

Upvotes: 0

Views: 900

Answers (1)

Buzz
Buzz

Reputation: 1907

If you have the whole thing as on string like this:

jstring = '{"label":"2017-06-01","value1":"250.730000"},{"label":"2017-06-02","value1":"250.730000"}'

then the dumps process sees this as two differnt objects and it can't process the information correctly. you need to put your string in a single object like this:

jstring = '{"first":{"label":"2017-06-01","value1":"250.730000"},"second":{"label":"2017-06-02","value1":"250.730000"}}'

or like this:

jstring = '[{"label":"2017-06-01","value1":"250.730000"},{"label":"2017-06-02","value1":"250.730000"}]'

that way the parser sees only one object

Upvotes: 1

Related Questions