How do I parse JSON in Javascript?

To parse JSON with JavaScript, you can use the JSON.parse(string, function) method. The JSON.parse() method converts (or decodes) a string containing JSON into a JavaScript object. The JSON.parse() method takes two parameters. The first parameter is the JSON string to parse, and the optional second parameter is a function that is called on each element and can transform the value (see example below). If you pass invalid JSON to the JSON.parse() method, you will get a SyntaxError exception. In this JSON string decoding example, we use the JSON.parse() method to convert a JSON into a JavaScript object. Click Execute to run the JavaScript JSON Parse Example online and see the result.
Loading...