views:

1158

answers:

2

I'm making requests to my server using jQuery.post() and my server is returning JSON objects (like { "var": "value", ... }. However, if any of the values contains a single quote (properly escaped like \'), jQuery fails to parse an otherwise valid JSON string. Here's an example of what I mean (done in Chrome's Console):

Chrome Console

Is this normal? Is there no way to properly pass a single quote via JSON?

+11  A: 

According to the state machine diagram on the JSON website, only escaped double-quote characters are allowed, not single-quotes. Single quote characters do not need to be escaped:

alt text

Justin Ethier
+1 for using the JSON.org diagram, very nice.
rick schott
A: 

Interesting. How are you generating your JSON on the server end? Are you using a library function (such as json_encode in PHP), or are you building the JSON string by hand?

The only thing that grabs my attention is the escape apostrophe (\'). Seeing as you're using double quotes, as you indeed should, there is no need to escape single quotes. I can't check if that is indeed the cause for your jQuery error, as I haven't updated to version 1.4.1 myself yet.

Aistina