{"id":51900477,"url":"https://github.com/drupol/json-sort","last_synced_at":"2026-07-26T14:04:55.247Z","repository":{"id":352586868,"uuid":"1213347033","full_name":"drupol/json-sort","owner":"drupol","description":"A command-line tool that sorts JSON files with a consistent key order, making them easier to read and maintain.","archived":false,"fork":false,"pushed_at":"2026-06-22T08:19:47.000Z","size":98,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2026-06-29T08:31:31.409Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"eupl-1.2","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/drupol.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"drupol"}},"created_at":"2026-04-17T09:32:01.000Z","updated_at":"2026-06-22T08:19:48.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/drupol/json-sort","commit_stats":null,"previous_names":["drupol/json-sort"],"tags_count":9,"template":false,"template_full_name":null,"purl":"pkg:github/drupol/json-sort","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drupol%2Fjson-sort","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drupol%2Fjson-sort/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drupol%2Fjson-sort/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drupol%2Fjson-sort/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/drupol","download_url":"https://codeload.github.com/drupol/json-sort/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/drupol%2Fjson-sort/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":35916664,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-07-20T02:08:10.276Z","status":"online","status_checked_at":"2026-07-26T02:00:06.503Z","response_time":89,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":"2026-07-26T14:04:54.427Z","updated_at":"2026-07-26T14:04:55.240Z","avatar_url":"https://github.com/drupol.png","language":"Rust","funding_links":["https://github.com/sponsors/drupol"],"categories":[],"sub_categories":[],"readme":"![GitHub stars][GitHub stars]\n[![NPM Version][NPM Version]][NPM package]\n[![Crates.io Version][Crates.io Version]][json-sort crates]\n[![Crates.io License][Crates.io License]][json-sort crates]\n[![Try online][try online badge]][try online link]\n[![Donate!][Donate!]][sponsor link]\n\n# JSON Sort\n\nThis project is a Rust rewrite of [`json-sort-cli`](https://github.com/tillig/json-sort-cli) with a few differences.\n\nIt is designed to make JSON files easier to compare by sorting object keys only. Array order is preserved, so lists are not modified.\n\nThanks to Rust's WebAssembly support, the same sorting logic is also available as a Node.js package.\n\n## Features\n\n- It is written in [Rust](https://rust-lang.org/) and it is tiny, less than 1.5MB.\n- It rewrites the original source file so object keys can be sorted without reformatting the whole document, while validating JSON string literals with [`serde_json`](https://crates.io/crates/serde_json).\n- It is multi-threaded and can process multiple files in parallel, which may improve performance on large codebases.\n- When a file is modified, existing whitespace, indentation, inline layout, and array order are preserved as much as possible.\n- It has a `--check` mode for CI usage, which only checks without modifying files.\n\n## Installation\n\n### Via Cargo\n\nYou can install the binary with Cargo:\n\n```sh\ncargo install json-sort\n```\n\n### Via Nixpkgs\n\nAvailable via the [`json-sort` package][json-sort package], the binary is called `json-sort`.\n\n### Via the source code\n\nClone the repository and run in the source code folder:\n\n```sh\ncargo build --release\n```\n\nThe binary will be in `target/release/json-sort`.\n\n### Via Node.js\n\nA Node.js package generated from the Rust WebAssembly build is available as [`json-sort-rs`][json-sort npm].\n\n```sh\nnpm install json-sort-rs\n```\n\n```js\nimport { sort_json_string } from \"json-sort-rs\";\n\nconst sorted = sort_json_string('{\"z\":1,\"a\":2}');\n\nconsole.log(sorted);\n```\n\n### Browser demo with WebAssembly\n\nThe library can also run in a browser through WebAssembly:\n\n```sh\njust serve\n```\n\nOpen \u003chttp://localhost:8080\u003e and use the page to sort JSON object keys locally\nin the browser.\n\nTry the online demo on GitHub Pages; the link is available in the badge at the top of this\nfile.\n\n### Via Nix\n\nYou can use the package from this repository with Nix. If you have Nix installed, you can run the tool directly:\n\n```sh\nnix run github:drupol/json-sort\n```\n\n### Treefmt module\n\nThis repository also exposes a reusable `treefmtModule` as `treefmtModules.default`, so you can add the\n`json-sort` formatter to any `treefmt` configuration without duplicating the setup.\n\n```nix\n  treefmt = {\n    imports = [\n      inputs.json-sort.treefmtModules.default\n    ];\n    projectRootFile = \"flake.nix\";\n    programs = {\n      json-sort.enable = true;\n    };\n  };\n```\n\nMake sure to add the `json-sort` flake input:\n\n```nix\n  inputs = {\n    # ... 8\u003c ...\n    json-sort.url = \"github:drupol/json-sort\";\n    # ... \u003e8 ...\n  };\n```\n\n## Usage\n\n### Command Line\n\n```sh\njson-sort [--fix] [--check] [--version] \u003cfile_or_dir_or_glob|-\u003e [\u003cother_files_or_dirs_or_globs\u003e]\n```\n\nIf you pass `-` as the only argument, `json-sort` will read JSON from standard input (stdin) and print the sorted result to standard output (stdout). This is useful for piping and shell usage.\n\n### VSCode Extension\n\nYou can integrate `json-sort` in VS Code using the [Custom Local Formatters extension](https://marketplace.visualstudio.com/items?itemName=jkillian.custom-local-formatters).\n\nAdd the following to `.vscode/settings.json`:\n\n```json\n{\n  \"customLocalFormatters.formatters\": [\n    {\n      \"command\": \"json-sort --fix -\",\n      \"languages\": [\"json\"]\n    }\n  ]\n}\n```\n\nThis runs `json-sort` as the formatter for JSON files.\n\nHow to use it:\n\n1. Install `json-sort`.\n2. Edit `.vscode/settings.json` and add the configuration above.\n3. Open a JSON file.\n4. Press `Shift+Ctrl+P`, run `Format Document With...`, then select `Custom Local Formatters`.\n5. Profit.\n\n### Main options\n\n- You can pass files, globs (e.g. '\\*.json'), or directories as arguments. Directories are searched recursively for `.json` files.\n- Resolved files are deduplicated before processing, so overlapping inputs are handled once.\n- When multiple files are resolved, they are processed in parallel.\n- Inputs that do not resolve to any files are reported as errors.\n- A single trailing newline at end of file is preserved and does not make an already sorted file fail checks.\n- You can also pass `-` as the only argument to read JSON from stdin and print the sorted result to stdout.\n- `--fix`: Update files with fixes instead of just reporting differences.\n- `--check`: Only check for unsorted files, never modify them (for CI usage). If both --fix and --check are set, no files will be modified.\n- `--version`: Print the CLI version and exit.\n- `--fix` exits successfully after applying all fixes, and exits non-zero only when an input or I/O error occurs.\n\n### Examples\n\n- Check sorting of a file:\n  ```sh\n  json-sort myfile.json\n  ```\n- Check sorting of all JSON files in a directory (recursively):\n  ```sh\n  json-sort mydir/\n  ```\n- Fix all JSON files in the folder (using a glob):\n  ```sh\n  json-sort --fix '*.json'\n  ```\n- Fix all JSON files in a directory (recursively):\n  ```sh\n  json-sort --fix mydir/\n  ```\n- CI check (fail if any file is not sorted, but do not modify anything):\n  ```sh\n  json-sort --check '*.json'\n  ```\n- Pipe JSON content and sort it (output to stdout):\n  ```sh\n  cat myfile.json | json-sort -\n  ```\n- Use with curl to pretty-print and sort remote JSON:\n  ```sh\n  curl -s https://api.example.com/data.json | json-sort -\n  ```\n\n## Behaviors\n\n### Comments\n\nStandard JSON does not support comments, but this tool accepts line comments `//` and block comments `/* */` and preserves them when rewriting the file. In practice, this makes the accepted input closer to JSONC than strict JSON.\n\nWhen object keys are reordered, comments and surrounding whitespace stay in their original layout positions.\n\n### Normalization\n\nThis tool preserves the original literal representation whenever possible:\n\n- **Unicode Escapes**: Escaped strings such as `\\u00e9` remain escaped if that is how they appear in the source.\n- **Numbers**: Number formatting, including scientific notation, is preserved as written.\n\n### Formatting\n\nThis tool does not apply a global pretty-print format. Instead, it rewrites only the object member order and keeps the surrounding formatting intact as much as possible.\n\nArrays are never reordered, and inline versus multi-line layout is preserved.\n\n## Recommended Tools\n\nFor advanced formatting and JSON manipulation, consider these tools:\n\n- [jaq]: A `jq` clone focussed on correctness, speed, and simplicity\n  ```sh\n  echo '{\"z\": 10, \"a\": 5, \"c\": 2}' | json-sort - | jaq .\n  ```\n- [Prettier]: An opinionated code formatter that supports JSON\n  ```sh\n  json-sort --fix myfile.json \u0026\u0026 prettier --write myfile.json\n  ```\n\n[GitHub stars]: https://img.shields.io/github/stars/drupol/json-sort.svg?style=flat-square\n[Donate!]: https://img.shields.io/badge/Sponsor-Github-brightgreen.svg?style=flat-square\n[sponsor link]: https://github.com/sponsors/drupol\n[`json-sort` package]: https://search.nixos.org/packages?channel=unstable\u0026from=0\u0026size=50\u0026sort=relevance\u0026type=packages\u0026query=json-sort\n[MiniJinja]: https://docs.rs/minijinja/\n[Crates.io License]: https://img.shields.io/crates/l/json-sort?style=flat-square\n[Crates.io Version]: https://img.shields.io/crates/v/json-sort?style=flat-square\n[json-sort package]: https://search.nixos.org/packages?channel=unstable\u0026from=0\u0026size=50\u0026sort=relevance\u0026type=packages\u0026query=json-sort\n[json-sort crates]: https://crates.io/crates/json-sort\n[json-sort npm]: https://www.npmjs.com/package/json-sort-rs\n[jaq]: https://github.com/01mf02/jaq\n[Prettier]: https://prettier.io/\n[try online badge]: https://img.shields.io/badge/Online_Demo-green?style=flat-square\n[try online link]: https://drupol.github.io/json-sort/\n[NPM Version]: https://img.shields.io/npm/v/json-sort-rs?style=flat-square\n[NPM package]: https://www.npmjs.com/package/json-sort-rs\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrupol%2Fjson-sort","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdrupol%2Fjson-sort","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdrupol%2Fjson-sort/lists"}