Posted 15 September 2021
by Robin La Fontaine

Share this blog:

Read more in Data Management

How do I use XML or JSON for information that can be in any order?

I presented a paper at the Balisage conference this year on the significance (or not!) of element order in XML, “ Element order is always important in XML, except when it isn’t ”. Part of this discussion included JSON. In fact the way that order is handled in the two formats is remarkably similar: XML elements are by definition ordered as are JSON array members. Similarly, an XML attribute is a name/value pair as is a JSON object member and both of these can appear in any order in a file. So any orderless information must have a name or key in both XML and JSON. This is not always the case though in real world data.

Should I specify the order in XML and JSON data?

One question that generated quite a lot of discussion was how best to treat information that has no order, i.e. the order of the elements makes no difference to the meaning. Let’s look at a small example to illustrate this.

© 2000-2025 DeltaXML Ltd. registered in England and Wales (Company No. 2528681), trading as DeltaXignia. All rights reserved