Parse error on JSON response containing URL value In my code it is making Ajax request for json data. For JSON output I am using drupal_json() function.

But on browser side it is invoking error handler instead of success handler and getting 'parsererror'.

The JSON data is like this:

{
    "affiliate_urls": {
        "4131": {
            "nid": "4131",
            "title": "play.com - Books",
            "file_path": "sites/default/files/playlogo.gif",
            "url_value": "http://www.play.com/Search.html?searchstring=asd+asdasd\x26searchsource=0\x26searchtype=allproducts"
        }
    }
}


When put on http://jsonlint.com/  I am getting this error:

Parse error on line 7:
...       "url_value": "http://www.play.com
-----------------------^
Expecting 'STRING', 'NUMBER', 'NULL', 'TRUE', 'FALSE', '{', '['


What is wrong with passing URL value over JSON? and still using drupal_json().

Please help on it.

Thanks
The problem is with drupal_to_js() which is called by drupal_json() to do the job. drupal_to_js() will perform str_replace(array("\r", "\n", "&lt;", "&gt;", "&amp;"), array('\r', '\n', '\x3c', '\x3e', '\x26'), addslashes($var)) to every string it receives. Converting '&amp;' to '\x26' is making problem to me here. Anyway I cannot use json_encode() because of PHP dependency (Drupal 6).

I solved the problem by URL encoding the URL value on server side using PHP function urlencode() when preparing JSON data. And URL decoded it on browser side by JS function decodeURI().