fast-json-stable-stringify
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Fast-json-stable-stringify is a deterministic JSON.stringify()
, specifically a quicker version of Substack's json-stable-stringify without jsonify. This NPM package enables developers to convert a JavaScript object into a JSON string in a reliable and consistent manner, without changes in the property order impacting the resulting JSON string. It's faster and efficient, making it a preferred choice for sizable JavaScript objects. It's versatile functionality allows for a custom comparison function to be passed in as well, providing developers with more control over the stringification process.
To use fast-json-stable-stringify, you'll first need to install it via NPM using the command npm install fast-json-stable-stringify
. After installation, use the require
function to make it available in your file. Use the following code as an example:
var stringify = require('fast-json-stable-stringify');
var obj = { c: 8, b: [{z:6,y:5,x:4},7], a: 3 };
console.log(stringify(obj)); // Will output: {"a":3,"b":[{"x":4,"y":5,"z":6},7],"c":8}
You can also provide custom comparison functions to determine the order of properties:
var stringify = require('fast-json-stable-stringify');
var obj = { c: 8, b: [{z:6,y:5,x:4},7], a: 3 };
var s = stringify(obj, function (a, b) {
return a.key < b.key ? 1 : -1;
});
console.log(s); // Results in: {"c":8,"b":[{"z":6,"y":5,"x":4},7],"a":3}
Objects with circular references can also be handled by setting opts.cycles
to true
.
For comprehensive documentation on fast-json-stable-stringify, please refer to the official GitHub repository (https://github.com/epoberezkin/fast-json-stable-stringify). The readme file in the repository provides detailed explanation and examples of the different ways to use this NPM package. You'll find basic usage examples, detailed options, and benchmarks for performance review.