{"name":"sorted-json","version":"0.3.0","main":"sorted-json.js","devDependencies":{"mocha":"6.0.2"},"scripts":{"test":"mocha"},"repository":{"type":"git","url":"git+https://github.com/pastgift/sorted-json-js.git"},"keywords":["json","sortify","stringify","sort"],"author":{"name":"Yiling Zhou","email":"pastgift@gmail.com"},"license":"MIT","bugs":{"url":"https://github.com/pastgift/sorted-json-js/issues"},"homepage":"https://github.com/pastgift/sorted-json-js","gitHead":"54a486b7b86bb167d6c7cd39dc33d53831ab8744","description":"Sort keys and array elements in a JSON.","_id":"sorted-json@0.3.0","_nodeVersion":"16.17.0","_npmVersion":"8.15.0","dist":{"integrity":"sha512-TsdYS8keXMENwDDIekhCt83DnV/n9wTGl+kAtYqjAWRDCYkTjFMuh7S3pXuIKhi4Yr43Mh7qyC1Zu57vI723Cw==","shasum":"9e949ba4f66355fc34f54ddfe641179451f08886","tarball":"http://registry-npm.ywwl.com/sorted-json/download/sorted-json-0.3.0.tgz","fileCount":6,"unpackedSize":10579,"signatures":[{"keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA","sig":"MEYCIQCjO8nnNwhEFRRCWhQ+F/fRMS7zEpT0+duKq6i+cltwzQIhAIqGKgPSrJHkPQUOptWNCY6Ke2G3XvSqoPcqjIkTFJbe"}],"size":3086,"noattachment":false,"key":"/sorted-json/-/sorted-json-0.3.0.tgz"},"_npmUser":{"name":"pastgift","email":"pastgift@gmail.com"},"directories":{},"maintainers":[{"name":"pastgift","email":"pastgift@gmail.com"}],"_npmOperationalInternal":{"host":"s3://npm-registry-packages-npm-production","tmp":"tmp/sorted-json_0.3.0_1735214271906_0.18108915606895182"},"_hasShrinkwrap":false,"readme":"# sorted-json-js\n\nSort keys and array elements in a JSON.\n\n## Quick Example 1:\n\nUsing `.sortify(...)` with `{ sortArray: true }` options to sort an object:\n\n```js\nvar sortedJSON = require('sorted-json');\n\nvar obj_1 = {\n  numberArray: [3, 1, 2],\n  anotherJSON: {\n    stringArray: ['cat', 'book', 'apple'],\n    numberA: 2,\n    numberB: 1\n  },\n  number1: 2,\n  number2: 1\n};\nconsole.log(sortedJSON.sortify(obj_1, { sortArray: true }));\n```\n\nOutput:\n\n```text\n{\n  anotherJSON: { numberA: 2, numberB: 1, stringArray: [ 'apple', 'book', 'cat' ] },\n  number1: 2,\n  number2: 1,\n  numberArray: [ 1, 2, 3 ]\n}\n```\n\n## Quick Example 2:\n\nUsing `.stringify(...)` to get a sorted JSON string:\n\n```js\nvar obj_2 = {\n  numberArray: [3, 1, 2],\n  anotherJSON: {\n    stringArray: ['cat', 'book', 'apple'],\n    numberA: 2,\n    numberB: 1\n  },\n  number1: 2,\n  number2: 1\n};\nconsole.log(sortedJSON.stringify(obj_2));\n```\n\nOutput:\n\n```text\n{\"anotherJSON\":{\"numberA\":2,\"numberB\":1,\"stringArray\":[\"cat\",\"book\",\"apple\"]},\"number1\":2,\"number2\":1,\"numberArray\":[3,1,2]}\n```\n\n# API:\n\n### .sortify(obj [, options])\n\nSort an object and return it.\n\n| Parameter           | Type     | Required | Default     | Description                                                                                                                      |\n| ------------------- | -------- | -------- | ----------- | -------------------------------------------------------------------------------------------------------------------------------- |\n| `obj`               | object   | Yes      |             | The object to sort                                                                                                               |\n| `options`           | object   |          | `{}`        | Sort options                                                                                                                     |\n| `options.sortBy`    | function |          | `undefined` | Specifies a function that defines the sort order. Same to `compareFunction` parameter in `Array.prototype.sort(compareFunction)` |\n| `options.sortKey`   | boolean  |          | `true`      | Sort the keys in `obj` or not                                                                                                    |\n| `options.sortArray` | boolean  |          | `true`      | Sort the array elements in `obj or not                                                                                           |\n| `options.stringify` | boolean  |          | `false`     | Output the stringified `obj` or not (Using `JSON.stringify()`)                                                                   |\n| `options.replacer`  |          |          |             | Parameter for `JSON.stringify()`                                                                                                 |\n| `options.space`     |          |          |             | Parameter for `JSON.stringify()`                                                                                                 |\n\n### .stringify(obj)\n\n| Parameter | Type   | Required | Default | Description        |\n| --------- | ------ | -------- | ------- | ------------------ |\n| `obj`     | object | Yes      |         | The object to sort |\n\n# Install:\n\n```shell\nnpm install sorted-json\n```\n\n# Test:\n\n```shell\nnpm test\n```\n\n# License\n\n[MIT](LICENSE)\n\n[downloads-image]: http://img.shields.io/npm/dm/sorted-json.svg\n\n[npm-url]: https://npmjs.org/package/sorted-json\n[npm-image]: http://img.shields.io/npm/v/sorted-json.svg\n","publish_time":1735214272223,"_cnpm_publish_time":1735214272223,"dist-tags":{"latest":"0.3.0"}}