Re:RESTful considered harmful
by jpollock on Friday July 24, 2015 @11:18AM
(#9942554)
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.
[ Parent
| on HN ]
Umm. 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'
?
Modern 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.
Not 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.