What do you mean by ordering? This is easy to miss in the linked "spec" (I did too at first) but there is a sentence:
"Object members must be sorted by ascending lexicographic order of their keys."
"Object members must be sorted by ascending lexicographic order of their keys."
Looking at the reference implementation, it contains
encode = encodeUtf8 . generate
So, the sorting is done before conversion to UTF-8.Relevant line, I think is
genObject hm = "{" <> foldl' go mempty (sortOn fst (HM.toList hm)) <> "}"
So, it uses Data.String’s sort order, which seems to be to lexicographic by Unicode code point (https://stackoverflow.com/a/3126287)⇒ implementations cannot sort the UTF-8 byte st sequences lexicographically. I think that’s a bad choice (if it was a choice and not an oversight)
I’ve never written a single line of Haskell, so corrections welcome.
Agree that specifying the keys to be ordered >by unicode code points< instead of >lexicographically< would be less ambiguous though.
Even if the spec requires it, I fear implementations will also canonicalize strings differently, breaking sort order.