I seem to remember that the specs are unclear if sorted hashes (aka objects) are allowed in JSON.
https://www.json.org/ is quite clear:
JSON is built on two structures:
- A collection of name/value pairs. In various languages, this is realized as an object, record, struct, dictionary, hash table, keyed list, or associative array.
- An ordered list of values. In most languages, this is realized as an array, vector, list, or sequence.
[...]
An object is an unordered set of name/value pairs.
So, "objects" are not sorted, they have no implied order, but you are free to write them out sorted by any criteria you like. But you should not expect that the ordering is retained.
BTW: I think the name "object" is an unfortunate choice, because it is no object in the sense of object-oriented programming.
Alexander
In reply to Re^2: Outputting JSON with sorted names/keys
by afoken
in thread Outputting JSON with sorted names/keys
by pryrt
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |