Working with Nested Data

JSON supports nested objects and arrays, allowing you to represent complex data structures. For example:

const employee = {
    "name": "Rajveer",
    "department": {
        "name": "Engineering",
        "location": "India"
    },
    "projects": [
        { "name": "Project A", "status": "In Progress" },
        { "name": "Project B", "status": "Completed" }
    ]
};

We can access nested properties using dot notation or bracket notation:

console.log(employee.department.name);  // Output: Engineering
console.log(employee["projects"][0].name);  // Output: Project A

How to Create and Manipulatinag JSON Data in javaScript?

The JavaScript Object Notation (JSON) is a lightweight data interchange format commonly used for transmitting data between the server and a web application. The JSON data is represented as the key-value pairs and is easy to read and write for both humans and machines. In JavaScript, JSON objects can be easily created and manipulated using built-in methods and functions.

Similar Reads

Creating JSON Data

JSON data consists of key-value pairs enclosed in curly braces{}, with keys and values separated by a colon “:". Arrays are represented using square brackets []. To create JSON data in JavaScript we can define an object literal with the key-value pairs and then use the JSON.stringify( ) method to convert the object into the JSON string....

Parsing JSON Data

To parse a JSON string back into a JavaScript object, you can use the JSON.parse() method....

Manipulating JSON Data

To manipulate JSON data in JavaScript we can parse a JSON string into the JavaScript object using JSON.parse() method. Once parsed, we can access and modify the properties of the JavaScript object as needed....

Working with Nested Data

JSON supports nested objects and arrays, allowing you to represent complex data structures. For example:...

Conclusion

JSON is a lightweight data interchange format that is widely used in web development. In JavaScript, you can easily create, parse, and manipulate JSON data using built-in methods like JSON.stringify() and JSON.parse(). Understanding how to work with JSON data is essential for handling data from APIs, storing configurations, and communicating between client and server applications....