osdir.com


[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Which one is the best JSON parser?


On Monday, June 27, 2016 at 9:31:04 AM UTC-4, Nagy L?szl? Zsolt wrote:
> On 2016-06-23, MRAB <python at mrabarnett.plus.com> wrote:
> >> On 2016-06-23 21:58, David Shi via Python-list wrote:
> >>> Can any one tell me?
> >>> Regards.
> >>> David
> >>>
> >> There's one in the standard library.
> > Which has always worked fine for me...
> Which always reminds me:
> 
> >>> import json
> >>> d = {0:1, False:2}
> >>> d
> {0: 2}
> >>> json.dumps(d)
> '{"0": 2}'
> >>>
> 
> WAT :-)

Python's booleans being ints is a remnant of history. I agree it would be
better for True and False to be unrelated to 1 and 0.

The conversion of 0 to "0" is because JSON can only use strings for keys in
objects. It might be better for dumps to fail if a non-string key is
encountered, but I'm not sure.

--Ned.