JSON is a standard text-based format for representing structured data based on JavaScript object syntax.
It is commonly used for transmitting data in web applications.
Initially, it was made for JavaScript, but many other languages have libraries to handle it as well.
JSON Structure
A JSON is a string whose format very much resembles JavaScript object literal format.
Here is a simple example of JSON.
let json_data = [
{
"name": "HoYa",
"age": 18,
"male": true,
"fruit": [
"apple",
"banana",
"cherry"
]
},
{
"name": "Jane",
"age": 16,
"male": false,
"fruit": [
"mango",
"grape"
]
}
];
let json_str = JSON.stringify(json_data);
console.log(`${typeof json_str}`);
// string
let json_obj = JSON.parse(json_str);
console.log(`${typeof json_obj}`);
// object
JSON format has many key-value pairs, and the key must be a string.
The JSON.stringify method converts an object into a JSON string.
The JSON.parse method converts a JSON string back into an object.
Arrays in JSON can be represented by [ ].
Reference
'Web > JavaScript' 카테고리의 다른 글
[Jest] JavaScript Code Unit Testing (0) | 2020.10.01 |
---|---|
[JavaScript] Callback, Promise, Async/Await (0) | 2020.09.18 |
[React] useState Hooks (0) | 2020.09.02 |
[React] prop-types (0) | 2020.09.02 |
[JavaScript] Object Destructuring (0) | 2020.09.02 |
댓글