
Security News
NIST Under Federal Audit for NVD Processing Backlog and Delays
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
json.sortify
Advanced tools
A deterministic version of JSON.stringify that sorts object keys alphabetically.
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
$ npm install json.sortify
let jsonSortify = require('json.sortify');
or
JSON.sortify = require('json.sortify');
or even
JSON.stringify = require('json.sortify');
JSON.sortify is fully compatible with JSON.stringify, so you can overwrite the native implementation without any problems.
Download JSON.sortify.js and save it to your server.
<script src="JSON.sortify.js"></script> <!-- will inject the JSON.sortify() function -->
Or, if you're using bower, type bower install json.sortify
.
<script src="bower_components/json.sortify/dist/JSON.sortify.js"></script>
JSON.sortify
can be used exactly like JSON.stringify
. As mentioned above, you can overwrite JSON.stringify if you want to:
<script src="JSON.sortify.js"></script>
<script>JSON.stringify = JSON.sortify</script>
You can also use JSON.sortify as an AMD module:
require(['json.sortify'], function (jsonSortify) { … });
Use JSON.sortify
exactly like JSON.stringify
. Refer to MDN:JSON/stringify for details.
JSON.sortify({a:1,b:2});
{"a":1,"b":2}
JSON.sortify({b:1,a:2,c:3,5:4});
{"5":4,"a":2,"b":1,"c":3}
JSON.sortify({b:1,a:2}, null, 2);
{
"a": 2,
"b": 1
}
JSON.sortify({b:1,foo:2,a:3}, ['a', 'foo'], 4);
{
"a": 3,
"foo": 2
}
JSON.sortify({b:1,foo:'woot',a:3}, function (key, value) {
return typeof value == 'string' ? value + '!!!' : value;
}, '\t');
{
"a": 3,
"b": 1,
"foo": "woot!!!"
}
FAQs
A deterministic version of JSON.stringify that sorts object keys alphabetically.
The npm package json.sortify receives a total of 2,156 weekly downloads. As such, json.sortify popularity was classified as popular.
We found that json.sortify demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
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.
Security News
As vulnerability data bottlenecks grow, the federal government is formally investigating NIST’s handling of the National Vulnerability Database.
Research
Security News
Socket’s Threat Research Team has uncovered 60 npm packages using post-install scripts to silently exfiltrate hostnames, IP addresses, DNS servers, and user directories to a Discord-controlled endpoint.
Security News
TypeScript Native Previews offers a 10x faster Go-based compiler, now available on npm for public testing with early editor and language support.