✅ CLI for sort JSONC files without mangling comments!
Works with regular JSON files too, of course!
See sort-jsonc for the underlying library.
sort-jsonc [options] <files>
Option | Alias | Description |
---|---|---|
--order |
-o |
The preferred order to sort keys as a comma-separated string. Prioritized over --order-file . Keys not in this list will be sorted alphabetically at the end. |
--order-file |
-O |
Path to a JSON file containing a list of strings in preferred order. Keys not in this list will be sorted alphabetically at the end. |
--remove-comments |
-c |
Whether to remove comments from the JSON. |
--spaces |
-S |
Number of spaces to indent the JSON. |
--silent |
-s |
Whether to suppress output. |
--help |
-v |
Show help info. |
$ sort-jsonc sort-jsonc path/to/file.jsonc
$ sort-jsonc path/to/file1.jsonc path/to/file2.jsonc
$ sort-jsonc sort-jsonc path/to/file.jsonc -o name,version,description
$ sort-jsonc sort-jsonc path/to/file.jsonc -O path/to/order.json
$ sort-jsonc sort-jsonc path/to/file.jsonc -c