- Array order is preserved by default
- Arrays are ordered collections, so their order is meaningful and left untouched. Sorting [3,1,2] into [1,2,3] would change what the document means. The optional "Sort arrays of scalars" switch reorders arrays that contain only strings, numbers or booleans, useful for normalising tag or permission lists where order carries no information. Arrays containing objects are never reordered.
- How keys are compared
- Keys are compared with locale-aware natural ordering, so item2 sorts before item10 rather than after it. That matches how people read numbered keys, though it differs from the byte ordering some tools use.
- Sorting does not change meaning
- JSON objects are formally unordered, so reordering keys yields an equivalent document. Be aware that some consumers do depend on the order they receive, particularly when a JSON document is used to produce a signature or checksum, sort before signing, never after.