0

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?

2
  • 2
    Try surrounding your jstring with brackets, like [{ "label": "2017-06-01", "value1": "250.730000" }, { "label": "2017-06-02", "value1": "250.730000" }] Commented Jun 5, 2017 at 21:19
  • I add [ , ] brackets but still won't run properly Edit in the end of a string ';' appear so it wasn't correct, sorry for my mistake Commented Jun 5, 2017 at 21:21

1 Answer 1

1

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.