Message from discussion simplejson 2.0 @ pylons 0.9.7
Received: by 10.114.25.19 with SMTP id 19mr1589336way.22.1238671831441;
Thu, 02 Apr 2009 04:30:31 -0700 (PDT)
Received: from rv-out-0708.google.com (rv-out-0708.google.com [184.108.40.206])
by gmr-mx.google.com with ESMTP id k32si449568wah.2.2009.04.02.04.30.31;
Thu, 02 Apr 2009 04:30:31 -0700 (PDT)
Received-SPF: neutral (google.com: 220.127.116.11 is neither permitted nor denied by best guess record for domain of b...@redivi.com) client-ip=18.104.22.168;
Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 22.214.171.124 is neither permitted nor denied by best guess record for domain of b...@redivi.com) smtp.mail=...@redivi.com
Received: by rv-out-0708.google.com with SMTP id l33so478235rvb.48
for <firstname.lastname@example.org>; Thu, 02 Apr 2009 04:30:31 -0700 (PDT)
Received: by 10.141.105.14 with SMTP id h14mr2858733rvm.91.1238671831284; Thu,
02 Apr 2009 04:30:31 -0700 (PDT)
Date: Thu, 2 Apr 2009 06:30:31 -0500
Subject: Re: simplejson 2.0 @ pylons 0.9.7
From: Bob Ippolito <b...@redivi.com>
Content-Type: text/plain; charset=UTF-8
On Thu, Apr 2, 2009 at 3:17 AM, Deron Meranda <deron.mera...@gmail.com> wro=
>> The problem indeed was with \n characters. I have tried jsonlint.com, bu=
>> doesn't give meaninful error messages, just "syntax error".
> (Don't confuse "jsonlint.com", the online service, with "jsonlint", which=
> command line tool that is part of my demjson python package)
> Unfortunately http://jsonlint.com/ is not really the best "lint". =C2=A0I=
t's a great
> service for the casual syntax error, and it's free and easy which is wond=
> But it can miss some of the edge cases, and as you've seen, doesn't
> always give you the most helpful messages.
> Fortunately, Python has several high quality JSON packages today (one of
> which has been adopted into of the standard Python 3.0 library). =C2=A0Af=
> having collaborated with most of the various package authors, they are al=
> today, for the most, very correct in their interpretation of the JSON
> standard and
> all its subtle nuances. =C2=A0So if one doesn't give you an understandabl=
> message, one of the others is likely to do so.
"one of which" is simplejson, and it is also in the Python 2.6+
standard library. It's called json there.
> Although JSON appears quite simple on the surface, it is actually surpris=
> intricate to implement parsers *correctly*. =C2=A0But I think that the JS=
> available for Python are probably the best (as in correct) implementation=
> available in any language.
> Oh, I'm not really trying to pimp my package, because simplejson is
> perfectly fine! =C2=A0But in case the need ever arises, I've been told th=
> demjson is one of the best for being able to parse badly-formed JSON
> (it has a toggleable strict/nonstrict mode); and it also generally gives
> fairly descriptive error messages. Unfortunately though, not even
> it will allow linefeeds inside of strings, even in it's loosest mode.
simplejson allows linefeeds in JSON if you pass strict=3DFalse (although
its strict parameter ONLY applies to control characters in strings).
Some of the pedanticness of simplejson is your fault for comparing it
to your package :)
>>> import simplejson
>>> simplejson.loads('"foo\nbar"', strict=3DFalse)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/mochi/lib/python2.5/site-packages/PIL/__init__.py", line 307, in l=
line 335, in decode
line 351, in raw_decode
ValueError: Invalid control character at: line 1 column 4 (char 4)
If anyone has any suggestions on how to format that error message so
that it is more clear then I'd be willing to give it a shot. I suppose
the repr of the control character in that exception would be useful?