{"name":"jQuery.parseJSON","type":"method","title":"jQuery.parseJSON()","deprecated":null,"removed":null,"desc":"Takes a well-formed JSON string and returns the resulting JavaScript object.","categories":["utilities","version/1.4.1"],"entries":[{"return":"Object","signatures":{"added":"1.4.1","argument":{"desc":"The JSON string to parse.","name":"json","type":"String"}},"examples":{"desc":"Parse a JSON string.","code":"\nvar obj = jQuery.parseJSON( '{ \"name\": \"John\" }' );\nalert( obj.name === \"John\" )\n;"},"longdesc":"\n

Passing in a malformed JSON string results in a JavaScript exception being thrown. For example, the following are all malformed JSON strings:

\n \n

The JSON standard does not permit \"control characters\" such as a tab or newline. An example like $.parseJSON( '{ \"testing\":\"1\\t2\\n3\" }' ) will throw an error in most implementations because the JavaScript parser converts the string's tab and newline escapes into literal tab and newline; doubling the backslashes like \"1\\\\t2\\\\n3\" yields expected results. This problem is often seen when injecting JSON into a JavaScript file from a server-side language such as PHP.

\n

Where the browser provides a native implementation of JSON.parse, jQuery uses it to parse the string. For details on the JSON format, see http://json.org/.

\n

Prior to jQuery 1.9, $.parseJSON returned null instead of throwing an error if it was passed an empty string, null, or undefined, even though those are not valid JSON.

\n "}]}