3 ms·
In fact, malformed XML is more frequent than malformed JSON, and it's not hard to see why. JSON types match the basic object model of many dynamic languages; n
by pwdisswordfish2 7y ago
In fact, malformed XML is more frequent than malformed JSON, and it's not hard to see why.
JSON types match the basic object model of many dynamic languages; not just JavaScript, but also Python and to a lesser extent Lua and PHP. So when people want to generate JSON, they usually do it the 'proper' way: by constructing a native structure consisting of built-in dictionaries and lists in their language of choice and then serialising it to a string. This always generates valid JSON syntax; the worst risk is that an empty dictionary could be mis-serialised as an empty array or vice versa, in languages that don't distinguish the two.
XML has no such easy support; when you generate XML, the least-effort solution is to use sprintf (or an equivalent), which creates the hazard of the programmer forgetting to escape syntax-significant characters (and let's not forget binary/text confusion in some languages).
JavaScript had to evolve E4X and JSX to solve the interpolation problem with XML. It didn't have to create any new syntax to support JSON; it is purely a library feature.
Of course, some programming languages favour neither, like C or Java.