4 ms·
The tweet at the top of the article says > This so far out of the spec it makes my ankles hurt. This is not in fact out of spec. The JSON spec does not define
by eridius 7y ago
The tweet at the top of the article says
> This so far out of the spec it makes my ankles hurt.
This is not in fact out of spec. The JSON spec does not define semantics here but instead quite explicitly leaves it up to the JSON processor and data interchange spec for what to do about ordering of objects.
- shortercode 7y agoIf the objects are not guaranteed to be in order, I would always consider them unordered. You could if both the producer and consumer are ordered, but as the OP noted this can cause problems later on and for no good reason. I'd use an array of key-value tuples if I wanted it to be ordered.
- al_form2000 7y agoUh, "no good reason" in this case means "I unchecked the box and nothing bad happened right away" which amounts to shallow analysis, to put it gently.
- Piskvorrr 7y agoThat was a twist ending, indeed. I was expecting a resolution, not "I gave it a good whack and guess what, that fixed it."
- dtech 7y ago> This is not in fact out of spec. The JSON spec does not define semantics [...] for what to do about ordering of objects. What? It is literally on the first page of json.org and section 1 of RFC 7159 [1] > An object is an unordered set of name/value pairs. > An object is an unordered collection of zero or more name/value pairs [1] https://tools.ietf.org/html/rfc7159#section-1 https://tools.ietf.org/html/rfc7159#section-1
- patrickthebold 7y agoThere are multiple standards. https://www.ecma-international.org/publications/standards/Ecma-404.htm https://www.ecma-international.org/publications/standards/Ec... Is more relaxed. >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. Also it's pretty clear that the keys must have an order going over the wire. And JavaScript objects (which aren't unrelated to JSON have an order now) https://www.stefanjudis.com/today-i-learned/property-order-is-predictable-in-javascript-objects-since-es2015/ https://www.stefanjudis.com/today-i-learned/property-order-i...