JavaScript | Add new attribute to JSON object Last Updated : 25 Jun, 2021 Comments Improve Suggest changes Like Article Like Report The task is to add a JSON attribute to the JSON object. To do so, Here are a few of the most used techniques discussed.Example 1: This example adds a prop_11 attribute to the myObj object via var key. html <!DOCTYPE HTML> <html> <head> <title> JavaScript | Add new attribute to JSON object. </title> </head> <body style="text-align:center;" id="body"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id="GFG_UP" style="font-size: 16px; font-weight: bold;"> </p> <button onclick="gfg_Run()"> Click here </button> <p id="GFG_DOWN" style="color:green; font-size: 20px; font-weight: bold;"> </p> <script> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); var myObj = { 'prop_1': { 'prop_12': 'value_12' } }; el_up.innerHTML = JSON.stringify(myObj); function gfg_Run() { var key = "prop_11"; myObj.prop_1[key] = "value_11"; el_down.innerHTML = JSON.stringify(myObj); } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: Example 2: This example adds a prop_11 attribute to the myObj with value value_11. html <!DOCTYPE HTML> <html> <head> <title> JavaScript | Add new attribute to JSON object. </title> </head> <body style="text-align:center;" id="body"> <h1 style="color:green;"> GeeksForGeeks </h1> <p id="GFG_UP" style="font-size: 16px; font-weight: bold;"> </p> <button onclick="gfg_Run()"> Click here </button> <p id="GFG_DOWN" style="color:green; font-size: 20px; font-weight: bold;"> </p> <script> var el_up = document.getElementById("GFG_UP"); var el_down = document.getElementById("GFG_DOWN"); var myObj = { 'prop_1': { 'prop_12': 'value_12' } }; el_up.innerHTML = JSON.stringify(myObj); function gfg_Run() { myObj.prop_1["prop_11"] = "value_11"; el_down.innerHTML = JSON.stringify(myObj); } </script> </body> </html> Output: Before clicking on the button: After clicking on the button: Comment More infoAdvertise with us Next Article JavaScript | Add new attribute to JSON object P PranchalKatiyar Follow Improve Article Tags : JavaScript Web Technologies JSON Similar Reads JavaScript | Remove a JSON attribute In this article, we will see how to remove a JSON attribute from the JSON object. To do this, there are few of the mostly used techniques discussed. First delete property needs to be discussed. Delete property to Remove a JSON Attribute This keyword deletes a property from an object: This keyword de 2 min read JavaScript- Add an Object to JS Array In JavaScript, arrays are used to store multiple values in a single variable, and objects are collections of properties and values. Sometimes, we may need to add an object to an array to manage data more effectively. These are the following ways to add an object to a JS array: Using JavaScript Array 4 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 JSON vs JavaScript Object JSON (JavaScript Object Notation) and JavaScript Objects are important for handling data in JavaScript, but they serve different purposes. JSON is a lightweight data format for transferring data, while JavaScript Objects are in-program data structures used for manipulation and logic.What is JSON?JSO 2 min read JavaScript JSON Objects JSON (JavaScript Object Notation) is a handy way to share data. It's easy for both people and computers to understand. In JavaScript, JSON helps organize data into simple objects. Let's explore how JSON works and why it's so useful for exchanging information.const jsonData = { "key1" : "value1", ... 3 min read Converting JSON text to JavaScript Object Pre-requisite: JavaScript JSON JSON (JavaScript Object Notation) is a lightweight data-interchange format. As its name suggests, JSON is derived from the JavaScript programming language, but itâs available for use by many languages including Python, Ruby, PHP, and Java and hence, it can be said as l 3 min read Deserializing a JSON into a JavaScript object 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 Notati 2 min read JavaScript Check if a key exists inside a JSON object When working with JSON objects in JavaScript, it's often necessary to check if a specific key exists within the object. This check is important, especially when dealing with dynamic or external data, to ensure that your code handles objects correctly and only accesses keys that are present. Below ar 3 min read 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 JSON Stringify an Array of Objects in JavaScript ? In JavaScript, the array of objects can be JSON stringified for easy data interchange and storage, enabling handling and transmission of structured data. The below approaches can be utilized to JSON stringify an array of objects.Table of ContentUsing JSON.stringify with a Replacer Function Using a C 3 min read Like