Hello,
On Fri, Mar 29, 2013 at 12:58 AM, Richard Kennard
<
richard.kenna...@gmail.com> wrote:
> Hi guys,
>
> I am the author of Metawidget (
http://metawidget.org), an Open Source tool
> that generates UIs from JSON files. I'm always interested in additional
> metadata I can gather to refine my UIs, so JSON Schema is of great interest
> to me.
>
> I would like to understand more about the decision to use 'objects with
> named properties' for JSON Schema...
>
> [ "prop1": { "length": 30, "required": true }, "prop2": { "length": 50 } ]
>
This is not valid JSON. A JSON array is: [ x1, x2, x3 ] where x1, x2,
x3 are JSON values -- any value, which means it can be an array, an
object, etc.
> ...as opposed to 'an array of objects'. For example:
>
> [ { "name": "prop1", "length": 30, "required": true }, { "name": "prop2",
> "length": 50 } ]
>
> Clearly the latter is not as easy to access (you can't use the dot notation
> to lookup by name), but a fundamental feature I require for Metawidget is to
> be able to specify ordering within the metadata.
>
> When adopting the 'objects with named properties' approach, how does JSON
> Schema convey ordering of properties?
>
The short answer:
* JSON Schema does not define any more ordering than what JSON (RFC
4627) defines;
* the only situation where order matters is in arrays.
Let us take two simple examples. This array:
[ 1, 2 ]
contains the same elements as:
[ 2, 1 ]
but they are _different_ arrays.
On the other hand:
{ "a": 1, "b", 2 }
and:
{ "b": 2, "a": 1 }
are the _same_ JSON values, since JSON objects have no notion of property order.
But there is no notion, in JSON, of "complex object ordering". There
is no way, in JSON, to say that for two objects o1 and o2, o1 is less
than o2 if o1's "name" is lexically less than o2's "name".
Relying on ordering of properties or whatever in any JSON value over
the wire would require a preliminary agreement between the _producer_
of this JSON value and its consumer. As I do Java and use Jackson, I
can testify that you _can_ bind Jackson so as to tell it to emit
property members, or even array elements, in a given order.
But in the general case? Don't count on it.
More broadly, JSON Schema describes JSON, and JSON only. Anything
beyond JSON, and this includes ordering, is beyond the scope of JSON
Schema altogether.
[note: there is also the problem with numeric value equality, but this
is beyond the scope of this discussion]
Hope this helps,
--
Francis Galiegue,
fgal...@gmail.com
JSON Schema in Java:
http://json-schema-validator.herokuapp.com