fast-json-stable-stringify
fast-json-stable-stringify
Deterministic JSON.stringify()
- a faster version of @substack's json-stable-strigify without jsonify.
You can also pass in a custom comparison function.
example
output:
methods
var str = stringify(obj, opts)
Return a deterministic stringified string str
from the object obj
.
options
cmp
If opts
is given, you can supply an opts.cmp
to have a custom comparison function for object keys. Your function opts.cmp
is called with these parameters:
For example, to sort on the object key names in reverse order you could write:
which results in the output string:
Or if you wanted to sort on the object values in reverse order, you could write:
which outputs:
cycles
Pass true
in opts.cycles
to stringify circular property as __cycle__
- the result will not be a valid JSON string in this case.
TypeError will be thrown in case of circular object without this option.
install
With npm do:
benchmark
To run benchmark (requires Node.js 6+):
Results:
license
Last updated