Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #71541 > unrolled thread

Re: problems decoding json objects

Started byBen Finney <ben@benfinney.id.au>
First post2014-05-14 19:20 +1000
Last post2014-05-14 19:20 +1000
Articles 1 — 1 participant

Back to article view | Back to comp.lang.python

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: problems decoding json objects Ben Finney <ben@benfinney.id.au> - 2014-05-14 19:20 +1000

#71541 — Re: problems decoding json objects

FromBen Finney <ben@benfinney.id.au>
Date2014-05-14 19:20 +1000
SubjectRe: problems decoding json objects
Message-ID<mailman.9993.1400059238.18130.python-list@python.org>
Tamer Higazi <th982a@googlemail.com> writes:

> myjs =
> '{"AVName":"Tamer","ANName":"Higazi","AAnschrift":"Bauerngasse","AHausnr":"1","APLZ":"55116","AOrt":"Mainz"},{"KontaktTel":["01234","11223344"],{"ZahlungsArt":"0"},{"ZugangsDaten":["tamer.higazi@nomail.com","mypass"]}'

That's not a valid JSON document. See <URL:http://json.org/>.

You appear to have three documents in a row, separated by commas. Or one
malformed document, missing its enclosure.

Or something else; that's the trouble with a malformed document, we
don't know what it should be.

> I get this error message:
>
> >>> JSD.decode(myjs)
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
>   File "/usr/lib64/python2.7/json/decoder.py", line 368, in decode
>     raise ValueError(errmsg("Extra data", s, end, len(s)))
> ValueError: Extra data: line 1 column 108 - line 1 column 220 (char 107
> - 219)

Right. The document ends there, and the rest of the string is trailing
garbage, which is an error.

> How do I solve this problem ?!

Fix the document. Where did it come from?

Best, don't put it directly in the Python source code as a string.
Ideally, have it as a distinct file, which you can examine in a text
editor with JSON highlighting; and run separately through a JSON parser
for correctness.

-- 
 \          “Isn't it enough to see that a garden is beautiful without |
  `\      having to believe that there are fairies at the bottom of it |
_o__)                                             too?” —Douglas Adams |
Ben Finney

[toc] | [standalone]


Back to top | Article view | comp.lang.python


csiph-web