[Web-SIG] Time a for JSON parser in the standard library?

Robert Brewer fumanchu at aminus.org
Sun Apr 6 08:45:10 CEST 2008


John Millikin wrote:
> On Sat, Apr 5, 2008 at 7:01 PM, Robert Brewer <fumanchu at aminus.org> wrote:
> > Re: Representation of Fractional Numbers, there are two solutions. If you
> > return decimals, people using JS on the other end are going to call float(d).
> > If you return floats, people not using JS on the other end are going to go
> > use a different library. I suggest the former is more acceptable than the
> > latter for a stdlib offering. Allowing the caller of parse() to choose
> > would be even better.
> 
> I don't understand what you mean, here. generate ([decimal.Decimal ('1.1')])
> -> '[1.1]', so a JavaScript user calling eval() on it would get a standard
> JavaScript float object without having to call float() explicitly.

Sorry, I wasn't describing what anyone would do in Javascript. Pythonistas receiving JSON numbers from a JS *sender*, who want Python floats, can call float(d) if they like if you hand them a Decimal object. Annoying but easy. People receiving JSON numbers from, say, a Python sender, can't call Decimal(f) if you hand them a float instance, at least not reliably. So they'll either go use some other jsonlib (bad) or start passing numbers in strings (worse).


Robert Brewr
fumanchu at aminus.org



More information about the Web-SIG mailing list