Trusted answers to developer questions
Trusted Answers to Developer Questions

Related Tags

javascript

How to convert JSON to JavaScript object

Nouman Abbasi

In this shot, we will learn how to convert a JSON string into a JavaScript object.

Syntax

JSON.parse(JSONstring)

Where JSONstring is the JSON string to parse. This method returns a JavaScript object.

JSON.parse(JSONstring) will raise an error if the passed string is not in a valid JSON format.

Code

Suppose you have a string JSON such as:

'{ "name": "John", "age": 20, "isYoung": true}'

To convert the above string into a JavaScript object, run:

let stringJSON = '{ "name": "John", "age": 20, "isYoung": true}';

let object = JSON.parse(stringJSON);

console.log(object);

RELATED TAGS

javascript

CONTRIBUTOR

Nouman Abbasi
Copyright ©2022 Educative, Inc. All rights reserved
RELATED COURSES

View all Courses

Keep Exploring