Hacker News new | past | comments | ask | show | jobs | submit login

The JSON parser in the Python standard library does support big ints, NaN, and +/-Infinity.

  >>> json.loads("NaN")
 nan
 >>> json.loads("Infinity")
 inf
 >>> json.loads("-Infinity")
 -inf
 >>> json.loads("1234567890"*20)
 123456789012345678901234567890123456789012345678901234567890
 123456789012345678901234567890123456789012345678901234567890
 123456789012345678901234567890123456789012345678901234567890
 12345678901234567890L
I haven't read the JSON spec, so I'm wondering whether this is actually standard JSON, whether it's an official extension of some kind to JSON, or whether the Python JSON parser is just being too clever.



Not standard.

> Numeric values that cannot be represented as sequences of digits (such as Infinity and NaN) are not permitted.

- http://www.ecma-international.org/publications/files/ECMA-ST...


Huh, the Python json module documentation admits that the Python behavior isn't standards-compliant.

https://docs.python.org/2/library/json.html#standard-complia...

It does claim that the support for arbitrary precision numbers is standards-compliant. Looking at the ECMA standard briefly, that seems to be correct to me: the official JSON grammar does allow arbitrary-precision, and disclaims restrictions on how a particular programming language interprets numbers.

I have to admit that I'm kind of concerned about the NaN and Infinity issue because I thought there was more uniformity among JSON parsers about what is or isn't legitimate JSON.




Consider applying for YC's Spring batch! Applications are open till Feb 11.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: