Deserializing a JSON into a JavaScript object Last Updated : 30 Sep, 2024 Comments Improve Suggest changes Like Article Like Report Deserializing a JSON into a JavaScript object refers to the process of converting a JSON (JavaScript Object Notation) formatted string into a native JavaScript object. This allows developers to work with the data in JavaScript by accessing its properties and methods directly.JavaScript Object Notation exchanges data to or from a web server or RESTFull API. The data received from a web server is always a string. To use that data you need to parse the data with JSON.parse() which will return a JavaScript Object or Array of Objects.Syntax: JSON.parse( string, function );Example 1: In this example, the JSON.parse() method parses the JSONString into a JavaScript object, allowing access to its properties just like any other JavaScript object. JavaScript // JSON string representing user data let jsonString = '{"name": "Alice", "age": 30, "city": "Wonderland"}'; // Deserializing the JSON string into a JavaScript object let user = JSON.parse(jsonString); // Accessing properties of the JavaScript object console.log("Name:", user.name); console.log("Age:", user.age); console.log("City:", user.city); OutputName: Alice Age: 30 City: Wonderland Example 2: In this example, the JSON.parse() method converts the productsJson string into a JavaScript array of objects, allowing iteration with forEach() to access and display product details. JavaScript // JSON string representing a list of products let productsJson = '[{"id": 1, "name": "Laptop","price": 1200},{"id": 2,"name": "Smartphone","price": 500}]'; // Deserializing the JSON string into an array of objects let products = JSON.parse(productsJson); // Looping through the array to access each product's properties products.forEach(product => { console.log(`Product ID: ${product.id}, Name: ${product.name}, Price: $${product.price}`); }); OutputProduct ID: 1, Name: Laptop, Price: $1200 Product ID: 2, Name: Smartphone, Price: $500 Comment More infoAdvertise with us Next Article Deserializing a JSON into a JavaScript object P Pankaj_Singh Follow Improve Article Tags : JavaScript Web Technologies JSON Similar Reads How to change JSON String into an Object in JavaScript ? In this article we are going to learn how to change JSON String into an object in javascript, JSON stands for JavaScript object notation. It is the plain format used frequently as a communication medium on the internet. It appears close to OOP language like JavaScript but cannot be accessed like Jav 3 min read How to Iterate JSON Object in JavaScript? In JavaScript, there are different ways to iterate over the properties of a JSON object. Letâs look at the most common techniques.1. Using for...in LoopThe for...in loop is a simple way to go through the properties of a JSON object. It loops over the keys of the object. Inside the loop, we can acces 4 min read JavaScript- Convert an Object to JS Array Objects in JavaScript are the most important data type and form the building blocks for modern JavaScript. These objects are quite different from JavaScriptâs primitive data types (Number, String, Boolean, null, undefined, and symbol). Methods to convert the Objects to JavaScript Array:1. Using Obje 3 min read Safely Turning a JSON String into an Object in JavaScript JSON (JavaScript Object Notation) is a data format used for storing and exchanging data. It is a lightweight and flexible format that can be easily parsed and understood by both humans and machines. When working with JSON data, it is important to know how to safely turn a JSON string into an object. 5 min read How to Check if Object is JSON in JavaScript ? JSON is used to store and exchange data in a structured format. To check if an object is JSON in JavaScript, you can use various approaches and methods. There are several possible approaches to check if the object is JSON in JavaScript which are as follows: Table of Content Using Constructor Type Ch 2 min read Like