Friday, November 16, 2018

escaping - Why is the slash an escapable character in JSON?











json.org states, that forward slashes (aka solidus, /) can be escaped:




"\/"


However, unescaped slashes are valid, too:



"/"


What's the rational behind this? Does it come from the Javascript roots? (I.e., "" is a problem in browser-based Javascript, see Douglas Crockford's comment) Or has it any other reason?



Answer



It seems, my first thought was correct.



'\/' === '/' in JavaScript, and JSON almost is valid JavaScript.
However, why are the other ignored escapes (like \z) not allowed in JSON?



The key for this was reading http://www.cs.tut.fi/~jkorpela/www/revsol.html, followed by http://www.w3.org/TR/html4/appendix/notes.html#h-B.3.2. The feature of the slash escape allows JSON to be embedded in HTML (as SGML) and XML.


No comments:

Post a Comment

plot explanation - Why did Peaches' mom hang on the tree? - Movies & TV

In the middle of the movie Ice Age: Continental Drift Peaches' mom asked Peaches to go to sleep. Then, she hung on the tree. This parti...