DEV Community

Discussion on: Hello XML, My Old Friend; I've Come To Encode You Again.

Collapse
 
erebos-manannan profile image
Erebos Manannán • Edited

Quick couple of comments:

1) JSON has no standardized way of expressing type information for each node
(XML has named tags for that). Some conventions do exist (e.g. a specifically
named "type" property in a node that tells the reader what this object
actually is) but that's a convention, not a standard.

json-ld.org/spec/latest/json-ld/ is a standard, though not 100% sure what you mean with the point so not 100% sure this fits your request, and it might easily exceed a lot of what you want from it too

4) Vanilla JSON (i.e. not JSON5) has no comments. No big deal for data
exchange, but being unable to put a comment to a dependency in a package.json
is more than annoying.

This just means that the person who decided to use .json format for their configuration was not particularly clever even though they probably thought they were. JSON is primarily a data transfer format, and should not be used for everything, incl. arbitrary configuration (AWS should die in a fire with their massive JSON configuration mess). XML would be (and is) also a mess for storing configuration for things.

For example YAML is MUCH better for that kind of use.

Collapse
 
martinhaeusler profile image
Martin Häusler

By "standard" I simply mean what the language supports on its own - not how you use it. In that regard, JSON has objects, arrays and properties. Nothing more, nothing less. XML has the concept of an identifier built natively into the language. Also, it is not uncommon to see an element reference another one by means of an XPath expression within the XML document itself. Yes, JSON can emulate all of that, no doubt about it, but I rarely ever encounter such cases in practice. I assume that people simply try to avoid these scenarios when working with JSON, or switch to a different format when they are inevitable. Even as a data interchange format, JSON does have its limitations. As a Java programmer, I would much rather work with XML, but in the web world, I guess that JavaScript devs prefer JSON.

I agree that using .json for the package configuration was not a very smart decision ;-) That's exactly what I meant with "enjoy responsibly".

One advantage that JSON definitly has over XML is that it is much easier to write manually than XML, and also more lightweight to read. I never worked with YAML so far, but it seems like a middle ground between XML and JSON.