- Why sort JSON keys?
- Three main reasons: stable diffs in version control (the same data always produces the same output), reproducible file hashes for cache invalidation, and easier visual scanning of large objects. Sorted keys are how npm writes package-lock.json, how Bun writes bun.lock, and how most build tools serialize manifests.
- What does this do to arrays?
- By default, nothing — arrays in JSON are ordered by definition, and reordering them changes meaning. Enable "sort arrays" only when the order is meaningless (a set of tags, a list of features) and you want canonical output. Mixed arrays are sorted by their JSON representation lexicographically.
- Are keys sorted at every level?
- Yes. The sort is recursive — every object at every depth gets the same treatment. A nested {"z": {"b": 1, "a": 2}} becomes {"z": {"a": 2, "b": 1}}.
- What sort order is used?
- JavaScript's default string sort, which is essentially Unicode code-point order. Uppercase letters come before lowercase, digits before letters, ASCII before non-ASCII. For human-readable case-insensitive sort, lowercase the keys first or normalise before sorting.
- Does sorting break my schema?
- No. JSON object keys have no defined order in the spec — every parser builds the same in-memory representation regardless of input order. Sort the file, re-run your tests, you will see no behavior change.
- Is my data private?
- Yes. Sorting runs locally in this browser tab. Nothing is uploaded or logged.