6 ms·
And we have XML. JSON is rediscovering XML Schema, XML DTDs etc, when we had those a quarter century ago already. It was so good when you could define the str
by theshrike79 1y ago
And we have XML.
JSON is rediscovering XML Schema, XML DTDs etc, when we had those a quarter century ago already.
It was so good when you could define the structure easily and validate it with standard tooling.
- ninkendo 1y agoThe problem I always had with XML is that it's not clear how to properly encode typical data. If I have a structure like this JSON: { "foo": "bar", "nested": { "nested_foo": "nested_bar", } } Should I do this in XML? <foo> bar </foo> <nested> <nested_foo> nested_bar </nested_foo> </nested> Or should I do this? <foo> bar </foo> <nested nested_foo="nested_bar"/> If your goal is to simply encode a data structure that looks more or less like a C-style struct (key/values, arrays, primitives), the concept of attributes on tags is superfluous, and introduces ambiguity in how to serialize something. To me, JSON is nice because it's essentially the minimum viable way of encoding a C-style struct (floating point behavior notwithstanding.) XML has extras like attributes, schemas, and DTDs, which may be useful, but they come at the cost of having additional syntax (<!DOCTYPE ...>, etc), which is auxiliary to the goal of encoding data structures, and thus makes it no longer as minimal. To me, JSON's approach of having a separate out-of-band definitions of schema (e.g. JSON schema) is the better approach because it's less opinionated, you only pay for it when you need it, and it doesn't require separate syntax. Leave validation to a validation step, my data is my data.
- wpm 1y agoI work with an API that returns XML that uses zero tag attributes. It’s all just tags, nested. It’s actually a joy to work with. I see some XML from other sources and it’s just awful. Everything that should be a nested tag is all jammed into an unreadable tag with attributes with no visual structure at all, spilling over the 80th column and word-wrapping in the terminal, it’s just like, what the hell. Why even use XML at that point?
- theshrike79 1y agoThe first one. Where you'd do attributes is like this: <foo type="address"> bar </foo> <nested type="resident_list"> <nested_foo type="resident"> nested_bar </nested_foo> </nested> A shitty example (you'd define types with schema), but you get the point. The data is in the tags, attributes are metadata, extra information that's needed during the process. This is what JSON is lacking, you can't give metadata to data, like defining types. The type definition needs to live NEXT to the data in special keys you need to check every time when parsing.
- p2detar 1y agoYou forgot to mention XSLT, which is just such a ridiculously powerful tool when you got XML data. It allows one to transform XML into XHTML or even other formats. Edit: Browsers also support this automatically, so you open an XML document and you get to see a rendered HTML from it. I had been tasked at least several times in my past jobs to develop XSLT scripts to transform data into user-readable content. I don't know of anyone that uses XSLT today and I have no idea if there is a JSON equivalent.
- rimunroe 1y ago> Browsers also support this automatically, so you open an XML document and you get to see a rendered HTML from it. Though as I understand it it's possible that this might not be the case for much longer: https://github.com/whatwg/html/issues/11523 https://github.com/whatwg/html/issues/11523
- oneeyedpigeon 1y agoI wrote a simple CMS a few years ago that used XSLT to assemble static pages from templates and data. It worked like a dream, although writing XSLT is not the easiest task!
- wpm 1y agoI use XSLT still, it’s a lot of fun. Mostly in shell scripts. jq is the closest thing for json, but it’s far messier to write longer filters than XSLT, and that’s saying something!
- theshrike79 1y agoI remember when Blizzard's web pages were just XML+XSLT. I was building some kind of parser for them and got confused for a second when my Python script returned bare XML when fetching the front page :D