5 ms·
I'd much rather deal with JSON than XML. XML is a document format, JSON is a data format. You extract data out of documents. JSON is 10 times easier to traverse
by vinceguidry 10y ago
I'd much rather deal with JSON than XML. XML is a document format, JSON is a data format. You extract data out of documents. JSON is 10 times easier to traverse than XML. XML is so difficult to traverse that you have to use a special language to do it cleanly, XPath. JSON, you just read it into whatever hash map data type your language has built-in and use your standard library.
- jimbokun 10y ago"XML is a document format" And works very well as a document format, and JSON works very poorly as a document format! So if you have documents (a novel, an article, a manual, etc.), XML is still a very nice choice. But was a mistake to use XML as a data format. (Just elaborating on your point.)
- maxxxxx 10y agoHow do you know that you are dealing with a document or data? Isn't a document just data too?
- vram22 10y agoI'm not an expert on the difference, but informally, I'd say that the difference is this: a "document" will have more and/or larger passages of text, and the fields are mainly meant as metadata to add meaning to it. A good example would be a real document like a book - when stored in an XML file, a lot of the content would be the text of the book, and you would have some XML elements like <book>, <chapter>, <section>, <TOC>, etc. But for "data", a good example would be an invoice or a purchase order or a part record - while they do have text, it will be mainly in the form of structured fields (typically not too long, unlike a chapter or section in a book), which can again be stored in XML elements. And this is where the siblings and others are arguing about - which (XML or JSON) is a better format for what type - document or data.
- jimbokun 10y ago"(a novel, an article, a manual, etc.)" So something meant to be read by humans. XML is nice for marking up the actual text with structure like chapters, sections, footnotes, references, formatting, etc. (thus, the ML in XML comes from "markup language") With JSON, there isn't really a notion of prose text to "mark up". It is structured data meant to be processed by machines. (Of course it is useful for humans to read and write JSON sometimes, but JSON is primarily meant to be input to or output from some computing process. You wouldn't sit down to read a JSON doucment unless you are some super weird programmer dude.)
- vinceguidry 10y agoData is sharply shape-constrained while documents aren't. You can easily look at data and devise traversal schemes to get at the information you want, whereas with documents, this isn't nearly as easy. If you're ingesting XML into a database, it's often easier to just put the whole XML in as a text field, whereas with JSON data, you can just extract the fields you want and insert them in.