jq keeps keys in the order they appeared in the input rather than normalising them. Two semantically identical documents whose keys are ordered differently therefore produce different jq output and a noisy diff, which defeats the common practice of piping both through jq before comparing.
'-S', or '--sort-keys', sorts object keys alphabetically at every level in the output, giving a canonical form suitable for diffing and for hashing. Combine with '--indent n' or with '-c' for compact single-line output when feeding another tool.
Related behaviour worth knowing when canonicalising: 'keys' returns an object's keys sorted, while 'keys_unsorted' returns them in document order, and the two differ in exactly the cases that matter. Arrays are never reordered, so a diff-friendly comparison of arrays whose element order is not significant needs an explicit 'sort' or 'sort_by'. Duplicate keys in the input are resolved last-one-wins during parsing, so a document with duplicates loses information before any filter runs.