[go: up one dir, main page]

0% found this document useful (0 votes)
17 views2 pages

Json

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views2 pages

Json

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

<!-- !

json -->

- Definition:

JSON (JavaScript Object Notation) is a lightweight data-interchange format


that is easy for humans to read and write, and easy for machines to parse and
generate.

Advantages of JSON:
- Human-Readable: JSON's structure is easy for developers to understand and
write.
- Lightweight: JSON is a minimal format that reduces the size of the data
being transmitted.
- Language-Independent: JSON can be used with many programming languages,
including JavaScript, Python, Ruby, Java, etc.

Syntax of JSON:

- Objects: Represented as key-value pairs enclosed in curly braces `{}`.


- Example:
{
"name": "virat",
"age": 30,
"city": "bangalore",
"fruits": ["Apple", "Banana", "Orange"]
}

Accessing JSON Data:


- Once parsed into a JavaScript object, you can access values using dot
notation or bracket notation.
- Example:
```javascript
const person = {
"name": "msd",
"age": 42,
"city": "chennai"
};
console.log(person.name);
console.log(person['city']);
Common Operations with JSON in JavaScript:

1. Parsing JSON:

- Converting a JSON string into a JavaScript object.


- Method: `JSON.parse()`

2. Stringifying JSON:
- Converting a JavaScript object into a JSON string.
- Method: `JSON.stringify()`

let obj1 ={
name:"rahul",
age:12,
isStudent:true,
marks : [10,20,30,40]
}

console.log(obj1)

// ! 1. JSON.stringify()

let jsonData = JSON.stringify(obj1);


console.log(jsonData)

// ! 2. JSON.parse()

let anotherObj = JSON.parse(jsonData)


console.log(anotherObj)

You might also like