problems decoding json objects

Ben Finney ben at benfinney.id.au
Wed May 14 05:20:13 EDT 2014


Tamer Higazi <th982a at googlemail.com> writes:

> myjs =
> '{"AVName":"Tamer","ANName":"Higazi","AAnschrift":"Bauerngasse","AHausnr":"1","APLZ":"55116","AOrt":"Mainz"},{"KontaktTel":["01234","11223344"],{"ZahlungsArt":"0"},{"ZugangsDaten":["tamer.higazi at 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




More information about the Python-list mailing list