https://github.com/tyilo/json_with_nan
JSON with NaN (and Infinity/-Infinity)
https://github.com/tyilo/json_with_nan
Last synced: 12 months ago
JSON representation
JSON with NaN (and Infinity/-Infinity)
- Host: GitHub
- URL: https://github.com/tyilo/json_with_nan
- Owner: tyilo
- Created: 2015-07-01T17:34:08.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2015-07-01T18:43:06.000Z (almost 11 years ago)
- Last Synced: 2024-04-24T03:16:50.415Z (about 2 years ago)
- Language: JavaScript
- Homepage:
- Size: 97.7 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
JSON with NaN (and Infinity/-Infinity)
======================================
Even though JSON is supported out of the box in modern browsers, none of them supports `NaN`, `Infinity` or `-Infinity` as values in JSON. This is because the JSON spec doesn't allow these values.
However sometimes it is useful to be able to pass all Javascript numbers around, so this project solves the problem by providing the functions `JSON.stringifyWithNaN` and `JSON.parseWithNaN`.
Strings created with `JSON.stringifyWithNaN` should be compatible with [Python's json module](https://docs.python.org/2/library/json.html) with `allow_nan=True` (which is the default).
Usage
-----
```
JSON.stringifyWithNaN(value[, replacer[, space]])
JSON.parseWithNaN(text[, reviver])
```
See the MDN article for [JSON.stringify](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/stringify) and [JSON.parse](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/JSON/parse) for more information about the parameters.