a variation of json-stable-stringify for deterministic JSON.stringify().
This repository is modified from json-stable-stringify.
The usage is similar to json-stable-stringify. If you used json-stable-stringify before,you can use this repository without changing your code. This repository passed all the tests of json-stable-stringify.
according to a pull request of the json-stable-stringify
var obj = { one: 1, two: { b: 4, a: [2,3] } };
var s = stringify(obj, { pretty: true });
console.log(s);
which outputs:
{one:1,two:{a:[2,3],b:4}}
var obj = { one: 1, two: { b: 4, a: [9,3] } };
var s = stringify(obj, { sortarrays: true });
console.log(s);
which outputs:
{"one":1,"two":{"a":[3,9],"b":4}}
according to normal JSON.stringify when you pass an array as the replacer argument,the array's values indicate the names of the properties in the object that should be included in the resulting JSON string
var obj = {a:1,b:2, c:3};
var s = stringify(obj, ["b", "a"]);
console.log(s);
which outputs:
{"b":2,"a":1}