Package Exports
- sort-json
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (sort-json) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
sort-json
It takes a JSON file and returns a copy of the same file, but with the sorted keys.
installation
[sudo] npm -g install sort-json
usage
const sortJson = require('sort-json');
const options1 = { ignoreCase: true, reverse: true, depth: 1 };
const copy = sortJson({ AA: 123, a: 1, b: 21 }, options1);
// copy => { b: 21, AA: 123, a: 1 }
sortJson.overwrite('some/absolute/path.json');
// sorts the json at absolute path and overwrites file, also returns sorted object
sortJson.overwrite(['some/absolute/path1.json', 'some/absolute/path2.json']);
// sorts the json at absolute paths and overwrites files, also returns array of sorted objects
CLI usage
sort-json file.json
=> sorts and overwrites file.json
-i
or --ignore-case
to ignore case when sorting.
-r
or --reverse
to reverse order z -> a
-d
or --depth
to chose the sorting depth on multidimensional objects
tests
npm test