3 ms·
<blockquote> Of course JSON has one (literally, one) tremendous advantage - it's human readable. </blockquote> I was surprised he didn't mention ease of use in
by josephscott 11y ago
<blockquote>
Of course JSON has one (literally, one) tremendous advantage - it's human readable.
</blockquote>
I was surprised he didn't mention ease of use inside JavaScript.
- jpollock 11y agoYou're not supposed to eval the strings, that way leads to xss. Since you're supposed to parse it no matter what, there's no difference between JSON and any other format.
- Drakim 11y agoNot true. While you should indeed not eval the string, once you have properly parsed it, you get a structured collection of objects and arrays that is very regular JavaScript structures. XML cannot offer the same, you get some much more abstract representation can easily be "wrong" if you don't follow the format as you extend it with more values, objects and arrays.
- jflatow 11y agoNot really, browsers still provide native JSON parsing ability - which is faster (and easier to implement) than most other parsing you would write inside JavaScript.
- bwy 11y agoUmm. I have no clue how you can say this. In JavaScript, JSON is unquestionably the easiest format to use. It may or may not be the same to parse, say, JSON and XML. But how is xmlDoc=new DOMParser().parseFromString(booksXml); newatt=xmlDoc.createAttribute("edition"); newatt.nodeValue="first"; x=xmlDoc.getElementsByTagName("title"); x[0].setAttributeNode(newatt); as easy to use as JSON.parse(booksJson).title.edition = 'first' ?
- xrstf 11y agoModern browsers ship with `JSON.parse()`, but not with ProtocolBuffer.parse(), Thrift.parse() or BSON.parse(). This advantage has nothing to do with eval(), but rather that JSON is pretty much built-in everywhere nowadays.
- mgr86 11y agoI haven't read the article yet, and while I prefer to work with JSON most of the time XML is much more human readable. And working in publishing we have a lot of XML floating around.
- cableshaft 11y agoI agree. When I am creating raw data to be consumed later (like for a personal project or something), I often find myself typing it up in XML and then using an XML -> JSON converter to change it to JSON for my actual code. I can just think in XML easier than remembering "Okay, so there's a bracket here, and a curly brace here, or is it curly brace and bracket? Do I need to include a key value here or not? Oh crap, I overlooked a comma again." I constantly have to send my JSON through lint, where I don't ever have to worry about that with XML.