JSON schema format, is attribute order considered for validating JSON?

Hi,

I’m working on generating the canonical JSON format, and I’m not sure if the attribute order should be the same as the one declared in the JSON Schemas, or if for JSON the order is not important.

I know for XML XSD order is important, and an attribute in the wrong order will return a validation error.

Thanks.

I think the order of properties is not important when validating JSON data.

See also RFC7159 :

An object is an unordered collection of zero or more name/value
pairs, where a name is a string and a value is a string, number,
boolean, null, object, or array.

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.

1 Like

Thanks you Sebastian, that is spot on!

I would say that if both XML and json are interchangeable in servers, then order could be important

Well, you are right, but this is only a consequence (or side effect) of XML Schema, not explicitly required by RM specs (as far as I know). There might be some old (legacy?) requirements on canonical form and relates back to computing hashes of archetypes.
In any case, it would be a at least a good (safer?) practice to stick to order of properties as they are defined in specs (reflected also in XSDs).

I guess in the server every format is mapped to the model, it is strange to have a format to format transformation, I would use the RM add an intermediate model for any transformation between formats. But if there such transformation, or should consider the ordering when generating an XML. I don’t see the issue. Can you expand?