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


Groups > comp.lang.python > #71541

Re: problems decoding json objects

Path csiph.com!usenet.pasdenom.info!weretis.net!feeder4.news.weretis.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail
Return-Path <python-python-list@m.gmane.org>
X-Original-To python-list@python.org
Delivered-To python-list@mail.python.org
X-Spam-Status OK 0.000
X-Spam-Evidence '*H*': 1.00; '*S*': 0.00; 'string.': 0.05; 'column': 0.07; 'json': 0.07; 'parser': 0.07; 'string': 0.09; 'data:': 0.09; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'separately': 0.09; 'trailing': 0.09; 'valueerror:': 0.09; 'python': 0.11; '(char': 0.16; '107': 0.16; 'correctness.': 0.16; 'distinct': 0.16; 'finney': 0.16; 'ideally,': 0.16; 'received:80.91.229.3': 0.16; 'received:plane.gmane.org': 0.16; 'separated': 0.16; 'subject:problems': 0.16; 'url:json': 0.16; 'fix': 0.17; 'file,': 0.19; '>>>': 0.22; 'header:User-Agent:1': 0.23; 'error': 0.23; 'source': 0.25; 'right.': 0.26; 'skip:" 30': 0.26; 'header:X -Complaints-To:1': 0.27; 'appear': 0.29; 'rest': 0.29; 'raise': 0.29; 'document.': 0.30; 'code': 0.31; '"",': 0.31; 'adams': 0.31; 'end,': 0.31; 'writes:': 0.31; 'file': 0.32; 'run': 0.32; 'text': 0.33; '(most': 0.33; 'trouble': 0.34; 'there,': 0.34; 'problem': 0.35; 'something': 0.35; 'editor': 0.35; 'there': 0.35; 'url:org': 0.36; 'should': 0.36; 'error.': 0.37; 'ben': 0.38; 'ends': 0.38; 'to:addr:python-list': 0.38; 'recent': 0.39; 'to:addr:python.org': 0.39; 'enough': 0.39; 'received:org': 0.40; 'how': 0.40; 'solve': 0.60; 'bottom': 0.67; 'believe': 0.68; 'beautiful': 0.68; 'fairies': 0.84; 'received:125': 0.84; 'examine': 0.93; 'garden': 0.95
X-Injected-Via-Gmane http://gmane.org/
To python-list@python.org
From Ben Finney <ben@benfinney.id.au>
Subject Re: problems decoding json objects
Date Wed, 14 May 2014 19:20:13 +1000
References <53732AFB.8080204@googlemail.com>
Mime-Version 1.0
Content-Type text/plain; charset=utf-8
Content-Transfer-Encoding 8bit
X-Gmane-NNTP-Posting-Host jigong.madmonks.org
X-Public-Key-ID 0xAC128405
X-Public-Key-Fingerprint 517C F14B B2F3 98B0 CB35 4855 B8B2 4C06 AC12 8405
X-Public-Key-URL http://www.benfinney.id.au/contact/bfinney-pubkey.asc
X-Post-From Ben Finney <bignose+hates-spam@benfinney.id.au>
User-Agent Gnus/5.13 (Gnus v5.13) Emacs/23.4 (gnu/linux)
Cancel-Lock sha1:eN3Y0sUr0qNpnH/NASNUetgO9fE=
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
Precedence list
List-Id General discussion list for the Python programming language <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
Newsgroups comp.lang.python
Message-ID <mailman.9993.1400059238.18130.python-list@python.org> (permalink)
Lines 41
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1400059238 news.xs4all.nl 2878 [2001:888:2000:d::a6]:48130
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:71541

Show key headers only | View raw


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

Back to comp.lang.python | Previous | Next | Find similar | Unroll thread


Thread

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

csiph-web