json-superstring
The native JSON.stringify()
method is quite fast, but it lacks safety checks for things like circular references and getter properties that throw errors. The json-superstring
module wraps JSON.stringify()
, and includes safety checks for these potentials issues.
Usage
Add json-superstring
as a dependency in package.json
:
$ npm install json-superstring -S
Then simply call json-superstring
...
const jsonSuperstring = require('json-superstring');
const data = {
foo: {
a: '1',
b: 2
}
};
data.foo.bar = data.foo;
console.log(jsonSuperstring(data));
API
Motivation
There are a number of safe JSON stringify modules out there, and this module has drawn inspiration from them (primarily safe-json-stringify
). However, the bulk of them focus on ensuring compatibility with the broadest set of legacy browsers as possible. This module is focused on usage within Node.js, and, so, can take advantage of a number of various structures in ECMA Script 2015 that significantly boost performance without working about legacy browser support.