Remix.run Logo
deaddodo 2 days ago

The main benefit of XML over JSON is that it is structured, and can be associated with Schema's for built in validation.

Obviously, that's only a benefit if you care about and utilize those features; most teams doing JSON integrations will just build those into the consumer in lieu of them being provided by the transport. But it is something that some people (especially larger enterprise organizations) value.

dolmen 2 days ago | parent | next [-]

JSON is structured (not plain text to be analyzed by an IA). JSON has JSON Schema.

In addition, JSON is easier to parse and to map to common data structures of programming languages.

jeroenhd 2 days ago | parent | next [-]

JSON Schema is an unofficial spec with a bunch of competitors and multiple versions, not all of which are compatible. I don't think you can compare it to XML schema validation.

I'm also not so sure about JSON being easier to map to common data structures. The lack of order guarantees within objects makes things like ordered maps quite annoying (you need to either use an array of entries with key and value, or an index within the mapped objects).

deaddodo 2 days ago | parent | prev [-]

"Structured" in this case refers to being able to be directly mapped to a data structure. Think protobuf and other similar transport mechanisms. The recipient knows what structure to expect because it's not a valid XML document if it's breaking those constraints.

JSON is not, it is closer to the PHP, JS, etc "object" type, which is an ephemeral object with arbitrary member associations.

And, to be clear, this is not a value judgement. They just excel in different fields. XML tends to be easier for strongly and strictly typed languages such as C/C++, C#, Java, etc where you can use the schema to generate your structs automatically. Vanilla JSON is easier for higher level languages that don't require you to manually create a mapping/validation level. JSON Schema tries to bridge that gap to a degree, but isn't built into the standard and isn't even universal.

But, ultimately, both are perfectly sufficient for either use case. It just depends on how much massaging you want to do to make them work.

abustamam 2 days ago | parent | prev [-]

Thanks, that's interesting to know. Given that we have json schema now though, what reason would someone use XML over Json now?

deaddodo 2 days ago | parent [-]

JSON Schema is largely an answer to people seeking that type of built-in validation. As I'm not a huge proponent for either (a tool is a tool and you work with it in its ecosystem), I don't have personal feelings on it's adequacy.

But, I would suspect, proponents of XML would still point to it's deeper typing system, document structure (especially the hierarchical features of it), and extremely mature ecosystem + tooling (such as XSLTs) as reasons to prefer it over JSON w/ JSON Schema.

abustamam 2 days ago | parent [-]

Gotcha! Thanks for the rundown. I started programming at the time when we were transitioning from XMLHTTPRequest to Fetch with json so I know of XML but basically only learned about json.