Allow serializing of Infinity/NaN/etc
Bug #325998 reported by
alecf
Affects | Status | Importance | Assigned to | Milestone | |
---|---|---|---|---|---|
jsonlib |
Won't Fix
|
Undecided
|
Unassigned |
Bug Description
I have some cases where I need to serialize Infinity/<inf> from Python out to JavaScript.
Attached is a patch that does this.
The patch also includes a fallback to UTF8/etc encoding when the encoder encounters a non-ascii 8-bit string.
To post a comment you must log in.
The literal values Infinity, -Infinity and NaN are features of JavaScript, but are not part of JSON[1]. If you serialize them directly, any conforming parser, including JSON.org's parser for JavaScript[2], will raise an exception.
This is similar to the problem of handling dates, which also have no explicit JSON representation. One popular solution is to encode unrepresentable values to strings, and then convert them back on the client side.
If at some future point the JSON spec is amended to include these values, jsonlib will be updated to include support for them. Until then, I have no plans to support non-standard extensions to the format.
[1] http:// www.ietf. org/rfc/ rfc4627. txt json.org/ json2.js
[2] http://