JSON.sortify
A deterministic version of JSON.stringify
that sorts object keys alphabetically.
Inspired by http://stackoverflow.com/questions/8931967/is-there-a-deterministic-equivalent-of-json-stringify
Install
$ npm install JSON.sortify
Usage
require('json.sortify'); // will inject the JSON.sortify() function
JSON.sortify
can be used exactly like JSON.stringify
JSON.sortify({a:1,b:2});
JSON.sortify({b:1,a:2});
JSON.sortify({b:1,a:2}, null, 2);
JSON.sortify({b:1,foo:2,a:3}, ['a', 'foo'], 4);
JSON.sortify({b:1,foo:'woot',a:3}, function (key, value) {
return typeof value == 'string' ? value + '!!!' : value;
}, '\t');
License
Apache-2.0