Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/sujon-ahmed/intro-to-json
https://github.com/sujon-ahmed/intro-to-json
Last synced: about 5 hours ago
JSON representation
- Host: GitHub
- URL: https://github.com/sujon-ahmed/intro-to-json
- Owner: Sujon-Ahmed
- License: mit
- Created: 2024-02-10T14:45:19.000Z (9 months ago)
- Default Branch: main
- Last Pushed: 2024-02-10T15:08:55.000Z (9 months ago)
- Last Synced: 2024-02-10T16:25:10.993Z (9 months ago)
- Size: 4.88 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Intro to JSON
## What is JSON?
JSON (Javascript Object Notation) is a lightweight data interchange format. It uses key-value pairs and is similar to object literals in JavaScript.The basic syntax consists of curly braces {}
for objects and square brackets [] for arrays.
## Create JSON Objects/Arrays
You can create JSON objects and arrays in JavaScript using their respective literal syntax.```js
// JSON Object
const person = {
name: "Sujon Ahmed",
age: 24,
email: "[email protected]"
};// JSON Array
const fruits = ["Apple", "Banana", "Orange", "Mango"];
```## Parse JSON
To convert a JSON string into a Javascript object, you can use JSON.parse().```js
const jsonString = '{"name": "Sujon Ahmed", "age": 24}';const person = JSON.parse(jsonString);
console.log(person.name); // Output: Sujon Ahmed
```## Stringify JS objects to JSON
To convert a JavaScript Object into a JSON string, you can use JSON.stringify().```js
const person = {
name: "Sujon Ahmed"
age: 24
};const jsonString = JSON.stringify(person);
console.log(jsonString);
// Output: '{"name": "Sujon Ahmed", "age": 24}'
```## Nested JSON
JSON supports nested structures, allowing you to create complex data hierarchies.```js
{
"name": "Sujon Ahmed",
"age": 24,
"address": {
"city": "Dhaka City",
"zipCode": "1207"
}
}
```## Working with JSON Arrays
JSON array can contain multiple values of different types, including other objects or arrays.```js
[
{
"name": "Sujon Ahmed",
"age": 24
},
{
"name": "Riman",
"age": 25
}
]
```