3 ms·
You'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 ot
by jpollock 11y ago
You'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.