json-sorter
Extracting a sorted result from a given JSON object or array even string, parse and stringify with JSON3.
Usage
'use srtrict';const jsonSorter = ;;
The first parameter json
could be an object or array, even a json string.
By default, options.parse
is true
, you can set it to false
so that it will not try to parse string to object or array.
Of course you can pass an user-defined parse function which will trigger a json-string parameter.
options.stringify
is used to judge whether to stringify the sorted result, and usually you don't need to set it.
If you don't set options.compare
, the json with be sorted according to the dictionary. It with be used to sort the keys of the parsed object like Array.prototype.sort
.
See Array.prototype.sort for more information.
A complex example is as follows:
const jsonSorter = ;const _ = ;);// outputs : '[{"key":3},{"key":2},{"key":1},{"key":{"d":2,"c":1,"b":4,"a":3}}]'
Yeah, as yo see it's very simple.
License
MIT License (Expat)