Sort names, keep array order
04Object property order becomes deterministic at every depth. Arrays keep their element order, even while objects inside them have their names sorted.
A separate object orders "10" before "2". Emit that order explicitly rather than relying on integer-key enumeration.
Source for this drawing: RFC 8785 · Read RFC section 3.2.3 ↗
New to this? Start hereA quick picture + helpful background
First, agree how to read the message.
An encoding tells a reader how to interpret bytes. A format tells it how values fit together. Correctly reading a value does not make that value trustworthy.
Helpful first, if these ideas are unfamiliar
These pictures are analogies to help you learn. The linked RFC explains the actual rules.
Terms in this drawing
Related RFCs and changes
“Updates” changes part of an earlier RFC. “Obsoletes” replaces it. This list shows selected related documents.
Sort object names recursively; never sort array elements.
- Properties MUST be sorted recursively, including objects found inside arrays. Array element order MUST NOT change.
- Compare raw, unescaped property names as unsigned UTF-16 code units, independent of locale. At the first differing unit, the smaller comes first; an otherwise equal prefix puts the shorter name first.
- UTF-8 byte order or Unicode code-point order can disagree with UTF-16 order. Also, numeric-looking keys are strings: "10" precedes "2". An ordinary object serializer that reorders integer keys is not by itself a JCS canonicalizer.
The worked input has nested objects and a two-element array. The separate supplementary-character comparison uses U+1F600 (D83D DE00) versus U+FF21: D83D is smaller than FF21, so the emoji name sorts first. No locale collation or normalization is involved.
Read the RFC section ↗