I have the following JSON string, encoded with PHP 5.2 json_encode():
{"foo":"\\."}
This JSON string is valid. You can check it out at http://www.jsonlint.com/
But the native JSON.parse() method (Chrome, Firefox), throws the following error, while parsing:
SyntaxError: Unexpected token ILLEGAL
Does anybody of you know, why I cannot parse escaped regular expression meta chars?
This example works:
{"foo":"\\bar"}
But this one fails also:
{"foo":"\\?"}
BTW: \. is just a simple test regular expression, which I want to run via javascript's RegExp object.
Thanks for your support,
Dyvor
'{"foo":"\\\\?"}'. So it seems you have to "double escape" the characters.'{"foo":"\\bar"}'seems to work (it throws no error) but the result will be{foo: "ar"}.