5 ms·
JSON either has those (namespaces, extensibility) or the advantage is slight at best (comments, canonical form). There is a real advantage of XML over JSON not
by mpyne 4y ago
JSON either has those (namespaces, extensibility) or the advantage is slight at best (comments, canonical form).
There is a real advantage of XML over JSON not mentioned though, which is its usefulness in annotating computer-readable data into an otherwise human-editable document. There's not a lot of these cases, and where they're at you're probably still better off using AsciiDoc, Markdown or even HTML instead, but those use cases are out there and JSON is awful for those.
- mcswell 4y ago"the advantage is slight at best (comments...)" I suppose that's true if the data is generated by machine and consumed by machine, and never edited or looked at by humans. But JSON seems to be used in a lot of datasets that humans do touch, like config files that you can edit. Visual Studio Code is one such user, and I've had to edit my own VSC config files. And I use comments, because http://catb.org/~esr/writings/unix-koans/prodigy.html http://catb.org/~esr/writings/unix-koans/prodigy.html. Fortunately, VSC allows comments between a // and a following newline.
- mpyne 4y ago> Fortunately, VSC allows comments between a // and a following newline. Yes, that's my point. If a human is required to look at the JSON it's not hard to find a parser that permits comments. So of course it would be supported if it was actually needed. Even without that though, you can do something like the trick I used in a JSON-based format: { "__comment": "For help with this file, go to http://wiki.example.com/ http://wiki.example.com/...", ... "foo": "..." } That does have the problem that your programs processing the JSON need to strip out keys with that name if it would interfere with the program. So it's probably easier just to add the line of code in your parser saying to permit comments. Meanwhile, XML comments have issues of their own, as you have to be familiar with SGML rules on how -- are handled to safely use or edit XML comments. So while they are nice to have it's not as if they have no nuance either.
- argomo 4y agoI'd add that another advantage of XML is that you get a powerful set of tools that are readily accessible across all "working" programming languages, often provided by first party libraries. Plus a lot of developers (and text editors) know the basic syntax. Granted, JSON has achieved this same level of universality, but everything else (excepting perhaps CSV files) either suffers from obscurity or from weak/ambiguous/competing specifications. The dream of semantically rich documents that XML provides (like, say, being able to cleanly interweave MathML, SVG, and XHTML in one document) is unmatched. I think we'd see a lot more XML usage if it hasn't been over-promised, over-delivered (WS-*), and over-used (enterprise Java). If XML had stuck to its lane (making a schema language like RelaxNG instead of XmlSchema, for one thing) it wouldn't have left such a bad taste in so many people's mouths.
- tokinonagare 4y agoHaving worked in the lexicographic space, XML is a format loved in that space because in the simplest forms it's understandable by non-technical people.