News for hackers. Stuff that matters.
Re:The Pretty JSON Revolution by fiddlerwoaroof on Tuesday February 23, 2021 @12:53PM (#26240371)
JavaScript objects are ordered maps (as are PHP’s arrays, iirc): it’s not common, but relying on this is specified behavior in JavaScript: it would be a little surprising for JSON object literals to follow a different rule.
Re:The Pretty JSON Revolution by dragonwriter on Tuesday February 23, 2021 @01:15PM (#26240626)
> JavaScript objects are ordered maps (as are PHP’s arrays, iirc): it’s not common, but relying on this is specified behavior in JavaScript: it would be a little surprising for JSON object literals to follow a different rule.

JSON object literals expressly follow a different rule (are expliclty unordered) per the IETF specs and have no specific significance to order at the JSON level though some might conceivably be introduced in ancillary specifications or tooling per the bigECMA spec.

JSON is syntactically a subset of JS but not semantically identical. Unambiguous order would require an array of one-entry objects in JSON.

Re:The Pretty JSON Revolution by fiddlerwoaroof on Tuesday February 23, 2021 @01:29PM (#26240831)
This isn’t true, the ECMA spec for JSON specifies that order is treated in an implementation-defined fashion.

> An object structure is represented as a pair of curly bracket tokens surrounding zero or more name/value pairs. A name is a string. A single colon token follows each name, separating the name from the value. A single comma token separates a value from a following name. The JSON syntax does not impose any restrictions on the strings used as names, does not require that name strings be unique, and does not assign any significance to the ordering of name/value pairs. These are all semantic considerations that may be defined by JSON processors or in specifications defining specific uses of JSON for data interchange.

https://www.ecma-international.org/wp-content/uploads/ECMA-4...

This wording allows a particular implementation to define its own meaning to the order of key-value pairs, or even to produce a multimap.