{"id":19181373,"url":"https://github.com/uid11/sort-json-keys","last_synced_at":"2025-05-07T23:07:00.192Z","repository":{"id":57366240,"uuid":"359570087","full_name":"uid11/sort-json-keys","owner":"uid11","description":"Sort JSON keys alphabetically at all levels","archived":false,"fork":false,"pushed_at":"2021-06-14T03:45:22.000Z","size":8,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-05-07T23:06:53.725Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/uid11.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-19T19:08:08.000Z","updated_at":"2023-06-11T04:46:32.000Z","dependencies_parsed_at":"2022-08-23T20:10:33.912Z","dependency_job_id":null,"html_url":"https://github.com/uid11/sort-json-keys","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uid11%2Fsort-json-keys","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uid11%2Fsort-json-keys/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uid11%2Fsort-json-keys/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/uid11%2Fsort-json-keys/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/uid11","download_url":"https://codeload.github.com/uid11/sort-json-keys/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":252968118,"owners_count":21833251,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-09T10:53:11.988Z","updated_at":"2025-05-07T23:07:00.169Z","avatar_url":"https://github.com/uid11.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# sort-json-keys\n\n[![NPM version][npm-image]][npm-url]\n[![dependencies: none][dependencies-none-image]][dependencies-none-url]\n[![code style: prettier][prettier-image]][prettier-url]\n[![Conventional Commits][conventional-commits-image]][conventional-commits-url]\n[![License MIT][license-image]][license-url]\n\nSort JSON keys alphabetically at all levels (for example for sorting `package-lock.json`).\n\n## Install\n\nRequires `node@14` or higher:\n\n```sh\nnpm install sort-json-keys --save-dev\n```\n\n## Usage\n\n### CLI\n\nSort all keys in the `foo.json` file in alphabetical order, indented by two spaces (default indentation):\n\n```sh\nnpx sort-json-keys foo.json\n```\n\nSorting the keys does not change the JS value of the JSON. In particular, array elements are not sorted.\n\nFor example this converts a JSON-file\n\n```json\n{ \"b\": 1, \"a\": { \"y\": 2, \"x\": 3 }, \"c\": [\"b\", \"a\"] }\n```\n\nto a file\n\n```json\n{\n  \"a\": {\n    \"x\": 3,\n    \"y\": 2\n  },\n  \"b\": 1,\n  \"c\": [\n    \"b\",\n    \"a\"\n  ]\n}\n```\n\nSort all keys in `foo.json` and `baz/bar.json` files in alphabetical order, indented by two spaces:\n\n```sh\nnpx sort-json-keys foo.json baz/bar.json\n```\n\nSort all keys in `foo.json` and `bar.json` files, indented by four spaces:\n\n```sh\nnpx sort-json-keys foo.json bar.json --indent 4\n```\n\nSort all keys in `foo.json` files without indentation (as a one-line file):\n\n```sh\nnpx sort-json-keys foo.json --indent 0\n```\n\n### JavaScript/TypeScript API\n\n```js\nimport sortJsonKeys from \"sort-json-keys\";\n// or\nimport { sortJsonKeys } from \"sort-json-keys\";\n\nconst json = { b: 1, a: 2 };\n\nconst sortedJson = sortJsonKeys(json); // { a: 2, b: 1 }\n```\n\n## License\n\n[MIT][license-url]\n\n[conventional-commits-image]: https://img.shields.io/badge/Conventional_Commits-1.0.0-yellow.svg \"Conventional Commits\"\n[conventional-commits-url]: https://conventionalcommits.org\n[dependencies-none-image]: https://img.shields.io/badge/dependencies-none-success.svg \"No dependencies\"\n[dependencies-none-url]: https://github.com/uid11/sort-json-keys/blob/main/package.json\n[license-image]: https://img.shields.io/badge/license-MIT-blue.svg \"The MIT License\"\n[license-url]: https://github.com/uid11/sort-json-keys/blob/main/LICENSE\n[npm-image]: https://img.shields.io/npm/v/sort-json-keys.svg \"sort-json-keys\"\n[npm-url]: https://www.npmjs.com/package/sort-json-keys\n[prettier-image]: https://img.shields.io/badge/code_style-prettier-ff69b4.svg \"Prettier code style\"\n[prettier-url]: https://github.com/prettier/prettier\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuid11%2Fsort-json-keys","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fuid11%2Fsort-json-keys","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fuid11%2Fsort-json-keys/lists"}