Why aren't double quotes and backslashes allowed in strings in the JSON standard?

Posted by Dan Herbert on Stack Overflow See other posts from Stack Overflow or by Dan Herbert
Published on 2011-01-02T02:42:24Z Indexed on 2011/01/02 2:53 UTC
Read the original article Hit count: 271

Filed under:
|

If I run this in a JavaScript console in Chrome or Firebug, it works fine.

JSON.parse('"\u0027"') // Escaped single-quote

But if I run either of these 2 lines in a Javascript console, it throws an error.

JSON.parse('"\u0022"') // Escaped double-quote
JSON.parse('"\u005C"') // Escaped backslash

RFC 4627 section 2.5 seems to imply that \ and " are allowed characters as long as they're properly escaped. The 2 browsers I've tried this in don't seem to allow it, however. Is there something I'm doing wrong here or are they really not allowed in strings? I've also tried using \" and \\ in place of \u0022 and \u005C respectively.

I feel like I'm just doing something very wrong, because I find it hard to believe that JSON would not allow these characters in strings, especially since the specification doesn't seem to mention anything that I could find saying they're not allowed.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about JSON