sfcode
An Online Competing and Development Environment
|
Deterministic JSON.stringify()
- a faster version of @substack's json-stable-strigify without jsonify.
You can also pass in a custom comparison function.
output:
Return a deterministic stringified string str
from the object obj
.
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:
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.
With npm do:
To run benchmark (requires Node.js 6+):
Results:
fast-json-stable-stringify package is a part of Tidelift enterprise subscription - it provides a centralised commercial support to open-source software users, in addition to the support provided by software maintainers.
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure. Please do NOT report security vulnerability via GitHub issues.