jQuery parseJSON() method
Some of the examples of malformed JSON strings that can cause an exception on passing are given as follows -
As similar to the above strings, multiple other malformed strings will cause an exception. The JSON standard also does not allow the appearance of control characters (such as tab or newline character) in the string.
Before jQuery version 1.9, if we pass an empty string, null, or undefined, the parseJSON() method returned null instead of throwing an error.
This method accepts a single parameter, which is defined as follows -
json: It is the valid JSON string to parse.
Now, let's understand the working of this method using an illustration.
Here, we are passing a well-formed JSON string to the parseJSON() method. We have to click the given button to get the output.Test it Now
After the execution of the above code, the output will be -
After clicking the given button, the output will be -