Published Jun 2, 2022
Contribute to Docs

The .parse() method returns a new value taken from a provided JSON string.


JSON.parse(jsonString, transformer);

The jsonString must contain valid JSON. Otherwise, a SyntaxError is thrown. Common JSON includes single objects or arrays of them. However, data types like booleans and numbers are also valid.

The transformer function is an optional parameter that operates directly on the parsed jsonString before the resulting transformation is returned.


In the example below, a valid JSON object is stored in a variable, myJSONString, and then passed into the .parse() method as an argument:

let myJSONString = '{"Hello": "World"}';

The output will look like this:

{ Hello: 'World' }

Codebyte Example

The following example further demonstrates how the .parse() method works:


All contributors

Looking to contribute?

Learn JavaScript on Codecademy