jQuery.parseJSON()    ** DEPRECATED **S2C Home « Utilities « jQuery.parseJSON()

Object creation from parsed JSON data.

Description

The jQuery.parseJSON() jQuery General utility method, returns a JavaScript Object object created from the specified well-formed JSON string.

Shorthand version $.parseJSON()

  • Passing a malformed JSON string to the jQuery.parseJSON() jQuery General utility method can result in an exception being thrown by the browser.
  • Passing null, undefined or an empty string to the jQuery.parseJSON() jQuery General utility method results in null being returned from the method.
  • If the browser being used provides a native implementation of JSON.parse, jQuery will use it to parse the string.

This method was deprecated in jQuery 3.0.

Syntax

Signature Description
jQuery.parseJSON( json )Return the JavaScript Object object created from the specified well-formed JSON string.

Parameters

Parameter Description Type
jsonThe JSON string to parse.String

Return

An Object object.

jQuery.parseJSON( json ) ExampleTop

Return a JavaScript Object object created from the specified well-formed JSON string.

In the example below when we press the button we parse some well formed JSON to a variable. Then we output a message displaying the properties of the Object object we created.



$(function(){
  $('#btn8').one('click', function(){
    var obj = jQuery.parseJSON('{"str1":"A stitch in time ","str2":"Saves nine"}');
    $('#div8').append(obj.str1 + obj.str2);
  });
});

div8. Some initial text.

Press the button below to action the above code: