Live data from Hacker News

JSON vs. XML

corecursive.com

121–130 of 252 posts

Re: JSON vs. XML

#121

Earlier quoted context omitted.

With XML, the complexity is the baseline, and it only goes up from there. With JSON, the complexity is just an option, the baseline is pretty simple. Also, good XML-tools are rare or expensive.

I guess, it depends on how you define XML baseline. You can have a very simple XML with only bare tags. It will work just fine. Arguably, it's even simpler than JSON that way. A basic parser for that it probably not more complex than a JSON parser. All the optional complexity that can go on top, though, is probably better specified for XML. Transformation is well defined for XML (XSLT) but not at all for JSON (I gues…

For a lot of XML you need to be able to support XML namespacing, and doing that adds a lot of complexity over the original pure XML.

At first XML namespacing sounds simple. Each tag and attribute will have an optional uri attached to it, no big deal right?

From reading through the specification one could be forgiven from assuming that the prefixes are just arbitrary mappings that a processor can ignore, or automatically remap to alternate prefixes.

For example, it is true that https://example.com/xyz" xmlns:def="5" rel="nofollow">https://example.com/xyz">5 (notice both namespaces are the same url) is equivalent to: 5" rel="nofollow">https://example.com/xyz">5.

Unfortunately, the data model also allows for content to reference the namespaces by prefix, and therefore every general xml processor that supports namespaces must keep around an application accessible mapping from the prefixes to namespaces, as the application may need to be able to access that information to interpret attributes or content. The only exception to this would be if the general XML processor insisted on having schema information for every namespace it might come across. In that scenario it would be able to tell if an attribute value of "abc:b" is really a string literal, or a reference to a namespace identifier (QNAME data type), where the namespace is whatever the current "abc" prefix is bound to, and the identifier is "b".

But obviously we don't want to add full schema support for a simple implementation, so we need to keep the mapping information around, just in case the application needs it. We also cannot easily offer nice features like changing a document to use preferred prefixes for certain namespaces, unless we also keep any prefixes that are used in values that could be interpreted as QNAMES, just in case they actually are, but our processor does not know, because it has omitted schema support for simplicity (or perhaps it included schema support, but does not have a schema available for some namespace).

And that is just the complexity that stems from one fairly small quirk in how XML works.

You also have no idea if an element content needs to preserve whitespace or not if you don't know the schema, and don't happen to have an xml:whitespace attribute present. Thus if you want to re-indent arbitrary xml for readability safely you could end up with something like this:

    5

Re: JSON vs. XML

#122
post #35

Earlier quoted context omitted.

I don’t write many APIs but every JSON schema I’ve created had been automatically generated by openapi tools. Even then I’ve found schemas of very little use, because everything gets validated on deserialization anyways. Client side validation usually already taken care of in practice because users should be serializing using the same type library that deserializes or reading the docs very thoroughly. JSON is so much…

That was the cause of the XML problems - everything was generated. Me? Schemas are a requirement in areas where you need to integrate over different technology / with different implementations. JSON Schema is in those contexts a bit of a kids toy compared to what XML can do.

I can still read the generated JSON.

Re: JSON vs. XML

#123
post #57

> Turned out JavaScript was the first language to give us lambdas, and that was an amazing breakthrough. I mean... with charity I can see the context and get it. But. What!? Overall fun read through history, even if definitely from Doug's perspective only. (As evidence by JavaScript being an originator of lambdas...) I do find the idea that JSON was as novel as history says it was kind of odd. I remember inlining jav…

The current XML standard is hot garbage since it completely disallows null characters even via "�" despite most languages now supporting nulls in the middle of strings. Also, JSON definitely allows schemas, primarily through the JSON schema standard, but I've also seen TypeScript notation used for this as well which has the convenience of being readable by more people (I strongly suspect more people know TypeScript than know either XML schemas or JSON schemas combined).

Re: JSON vs. XML

#124

Earlier quoted context omitted.

The Complexity of XML reminds me of something from Adam Bosworth's ISCOC04 Talk [0]. To me, the big takeaway is that HTML succeeded because of it's limitations, not despite of them. JSON seems very simple compared to XML. XML seems to be very powerful, but also very complex - it's like, if all you need to do is pick your kids up from Soccer Practice, you don't need the powerfullness (complexity) of the Space Shuttle…

But you don't have to use any more of the XML-related standards than you want to. You can ignore schemas, and add-on technologies like XPATH and XSLT and just use XML as a hierarchical tag-value format, just like JSON. At this level they are both about equal in complexity: JSON has data types that XML doesn't, and XML has attributes and CDATA that JSON doesn't. JSON syntax is more succinct, but XML syntax is more reg…

XML is good for documents that don't have a regular markup (XHTML, DocBook, JATS, MathML, etc.) where you can mix content elements -- e.g. italic annotations.

JSON is good for structured data/records such as serialized data structures found in RPC protocols.

They both have their own pros and cons that make them suited to different use cases. Choose the one that best suites your data model and use cases.

Re: JSON vs. XML

#125
I worked on a customized ejabberd at a company for years, drinking all the XMPP kool-aid and becoming very familiar with XML along the way. Slowly we all began to realize how bad XML was. We eventually put our custom extensions' data into JSON just embedded inside the XML. Says a lot that such a hack was actually an improvement.

The other two premier XML use cases I can think of are

1. RSS: Last time I did this, ironically I built the payload with a JSON-API'd lib that deals with the XML drama for me. Worked fine.

2. Configs. Rarely are these done in XML anymore. Human readability matters for configs. But there are also better options than JSON for this.

Re: JSON vs. XML

#126

Earlier quoted context omitted.

Baseline for XML would be a document that doesn't use schemas, namespaces, attributes, or any of the SGML legacy stuff like DTDs and PCDATA. Such a document is essentially as simple as the equivalent JSON.

Even that is more complicated than JSON.

Care to elaborate?

Re: JSON vs. XML

#127
I'll never understand the hating that xml tends to get around here.

Choose the right tool for the job at hand. Sometimes json is the right choice, sometimes xml is. Not everything is a webapp.

Re: JSON vs. XML

#128
post #46

From another interview: >The best thing we can do today to JavaScript is to retire it. Twenty years ago, I was one of the few advocates for JavaScript. Its cobbling together of nested functions and dynamic objects was brilliant. I spent a decade trying to correct its flaws. I had a minor success with ES5. But since then, there has been strong interest in further bloating the language instead of making it better. So J…

[dead]

Re: JSON vs. XML

#130
post #6

Honestly, I would relegate XML to application configuration. Trying to communicate with it with something like HTTP requests/responses is absurd.

I just had to comment on the irony of this comment being embedded in a document that is delivered via HTTP and very close to valid XML. Even if XHTML died on the wayside, HTML is imho a stereotypical example where XML is a good fit. Most of the complexity has valid use cases, and it's mostly obvious what should be an attribute and what should be content of the tag. And at least in HTML 4 you even had a doctype tag fi…

> HTML is imho a stereotypical example where XML is a good fit

Indeed, this was what XML was created for. From W3C's XML specification:

> The Extensible Markup Language (XML) is a subset of SGML that is completely described in this document. Its goal is to enable generic SGML to be served, received, and processed on the Web in the way that is now possible with HTML.

Honestly, what's absurd is GP comment's cluelessness.

Post reply on HN