[Pharo-users] Is it bad to have an order NeoJsonObject?

Richard O'Keefe raoknz at gmail.com
Mon Jun 11 21:54:33 EDT 2018


Herbert Vojčík
​wrote " it is already part of the spec a few years already that
enumeration on the object keys MUST respect the order in which keys
were created".

I quoted two specs: json.org and the ECMA one.  The current RFC
for JSON is, I believe, RFC 8259, which says

   JSON parsing libraries have been observed to differ as to whether or
   not they make the ordering of object members visible to calling
   software.  Implementations whose behavior does not depend on member
   ordering will be interoperable in the sense that they will not be
   affected by these differences.

What this is saying is that some JSON libraries do preserve order and
some do NOT.  There is no "de facto" standard specifying order
preservation.  What's more, the language is warning you that if you rely
on order, you should NOT expect your program to interoperate with
anything else and it is your fault if it doesn't.

If there is some other specification for JSON that requires order to be
preserved, tell us where to find it.

This is not about JavaScript.  JSON is not strictly compatible with

JavaScript anyway.  Consider Python:

>>> json.loads('{"a":1,"b":2}')
{u'a': 1, u'b': 2}
>>> json.loads('{"b":2,"a":1}')
{u'a': 1, u'b': 2}
​Using JSON::Parse in Perl gives the same result; the order does not

matter.


I could go on all day listing JSON libraries, tools, and interfaces

that either never preserve key order or make that an esoteric use-

at-your-own-peril option.
​
When you are designing a protocol using JSON syntax,
and you want an ordered association between keys and
values, you can interoperably use something like

{ "__isOrderedObject__": true
, "keys":   ["a","b"]
, "values": ​[1,  2  ]
}

Just to repeat: if you can find any ISO, ECMA, ITU, or IETF
specification that says key order should be preserved, let's
hear about it.  I have three JSON parsers I've written, and
I want them to be right.  Not like the brand X package that
says it can sometimes fail to read back JSON that it wrote.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pharo.org/pipermail/pharo-users_lists.pharo.org/attachments/20180612/2c25ed75/attachment-0001.html>


More information about the Pharo-users mailing list