New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

json.sortify

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json.sortify

A deterministic version of JSON.stringify that sorts object keys alphabetically.

1.0.1
Source
npm
Version published
Weekly downloads
3.6K
9.99%
Maintainers
1
Weekly downloads
 
Created
Source

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

// basic:
JSON.sortify({a:1,b:2}); /*
{"a":1,"b":2}

sorting: */
JSON.sortify({b:1,a:2}); /*
{"a":2,"b":1}

indentation: */
JSON.sortify({b:1,a:2}, null, 2); /*
{
  "a": 2,
  "b": 1
}

key whitelist: */
JSON.sortify({b:1,foo:2,a:3}, ['a', 'foo'], 4); /*
{
    "a": 3,
    "foo": 2
}

replacer function: */
JSON.sortify({b:1,foo:'woot',a:3}, function (key, value) {
    return typeof value == 'string' ? value + '!!!' : value;
}, '\t'); /*
{
        "a": 3,
        "b": 1,
        "foo": "woot!!!"
}
*/

License

Apache-2.0

Keywords

JSON

FAQs

Package last updated on 20 Jul 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts