Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
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)
Return-Path: <b...@redivi.com>
Received: from rv-out-0708.google.com (rv-out-0708.google.com [209.85.198.246])
        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: 209.85.198.246 is neither permitted nor denied by best guess record for domain of b...@redivi.com) client-ip=209.85.198.246;
Authentication-Results: gmr-mx.google.com; spf=neutral (google.com: 209.85.198.246 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 <pylons-discuss@googlegroups.com>; Thu, 02 Apr 2009 04:30:31 -0700 (PDT)
MIME-Version: 1.0
Received: by 10.141.105.14 with SMTP id h14mr2858733rvm.91.1238671831284; Thu, 
	02 Apr 2009 04:30:31 -0700 (PDT)
In-Reply-To: <5c06fa770904020117kb027420u59408ea7695a98f8@mail.gmail.com>
References: <b11e164d0904020001n354647bag7925de9ee18c7334@mail.gmail.com>
	 <5c06fa770904020018t4da51472q17bef05dd8bf1970@mail.gmail.com>
	 <b11e164d0904020025u9bc4f5cl50c842035bf83ab4@mail.gmail.com>
	 <5c06fa770904020117kb027420u59408ea7695a98f8@mail.gmail.com>
Date: Thu, 2 Apr 2009 06:30:31 -0500
Message-ID: <6a36e7290904020430g5cffe5br3648152f2672830c@mail.gmail.com>
Subject: Re: simplejson 2.0 @ pylons 0.9.7
From: Bob Ippolito <b...@redivi.com>
To: pylons-discuss@googlegroups.com
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: quoted-printable

On Thu, Apr 2, 2009 at 3:17 AM, Deron Meranda <deron.mera...@gmail.com> wro=
te:
>
>> The problem indeed was with \n characters. I have tried jsonlint.com, bu=
t it
>> doesn't give meaninful error messages, just "syntax error".
>
> (Don't confuse "jsonlint.com", the online service, with "jsonlint", which=
 is a
> 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=
erful!
> 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=
ter
> having collaborated with most of the various package authors, they are al=
l
> 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=
e error
> 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=
ingly
> intricate to implement parsers *correctly*. =C2=A0But I think that the JS=
ON modules
> available for Python are probably the best (as in correct) implementation=
s
> 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=
at my
> 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)
'foo\nbar'
>>> simplejson.loads('"foo\nbar"')
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=
oads

  File "/mochi/lib/python2.5/site-packages/simplejson-2.0.9-py2.5-macosx-10=
.3-i386.egg/simplejson/decoder.py",
line 335, in decode
  File "/mochi/lib/python2.5/site-packages/simplejson-2.0.9-py2.5-macosx-10=
.3-i386.egg/simplejson/decoder.py",
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?

-bob