We recently had the debate at my company of do we force order on JSON
or not. The answer was NO!! because clients are free to put whatever
sort order needed into the JSON and ordering of results is an XML
Schema (WSDL) solution / opportunity that JSON simplifies for clients.
I put the Null value example in the same category of issue.
Dale
2012/4/16 Guilherme Gössling <ggu...@gmail.com>:
> I put the Null value example in the same category of issue.
Agreed. Though, the difference between {"field":"null"} (the string n, u, l, l) and {"field":null} (the null value) is still worth some attention ;-)
Jack Repenning
Things should be made as simple as possible --
and no simpler!
-- Albert Einstein
Many JSON libraries, especially in dynamic languages, expose JSON objects as dictionaries. Thus, there is no way for a JSON producer to define order.
Many applications deal with infinite streams of data. Some of these have trees that can be arbitrary depth. Thus, they need stream serialization. Since there are app-level concerns, they need to guarantee that some information always happens before the first possibly-recursive part of the payload.
In our case, we made the ordering constraint optional and added a header to indicate whether the content was "stream parsable" (passed our ordering constraints). We didn't fully-order, but we did find places where certain fields needed to appear first. We also added a way to request that a response be given in stream order if possible (in many cases it is possible but more expensive).
This worked pretty well. The ordering allows a performance & scaling optimization. But if you know that you won't be doing things at massive scale, then you can ignore the constraints and just buffer everything.
Arlo
When serializing, a NULL dynamic property is defined to be exactly the same as a missing one. So we elide them.
All static properties are always represented. This makes it easier on libraries that choose to direct-map the payload to a static type.
This works pretty well for us, but requires that the server be able to declare its type system in a machine-readable fashion.
Arlo