What is JSON?

What is JSON? | Code Architects

JSON is JavaScript Object Notation. JSON is a lightweight format for storing and transporting data. JSON is often used when data is sent from a server to a web page. It is easy for machine to parse and generate. JSON supports

JSON Syntax Rules:

  • Data is in name/value pairs
  • Data is separated by commas
  • Curly braces hold objects
  • Square brackets hold arrays.
{
    "id": 1,
    "name": "Code Architects",
    "url": "https://teamcodearchitects.com"
}

JSON Stringify

A JSON object can be converted to JSON by using JSON.stringify() which is sent to browser from a Web Server. Taking JavaScript object and transforming to JSON String.

let obj = {
  firstName: "John",
  lastName: "Doe"
};
let jsonExample = JSON.stringify(obj);
console.log(jsonExample);

// {"firstName":"John","lastName":"Doe"}

JSON Parse

JSON.parse() takes the JSON string as an input and transforms it into JavaScript Object.

let str = '{"firstName":"John","lastName":"Doe"}';
let obj = JSON.parse(str);

console.log(obj);
/* {
  firstName: "John",
  lastName: "Doe"
} */

You also can modify or delete the values in these objects using both dot and bracket notation. In order to delete a property, use the delete keyword.


Thank you for reading this blog about What is JSON 🎇

Leave a Comment

Comments

No comments yet. Why don’t you start the discussion?

Leave a Reply

Your email address will not be published. Required fields are marked *

18 + 3 =