Member-only story
JSON — JavaScript Object Notation
JSON, or JavaScript Object Notation, is a lightweight format used for storing and exchanging data.
Imagine it as a universal language for data that both humans and machines can easily understand.
JSON is structured in a way that uses key-value pairs, similar to how you might organize information in a table. This makes it easy to read and write, which is why it’s widely used in web applications to send and receive data between a server and a client.
For example, if you wanted to share information about a person, you could represent it in JSON like this:
{
"name": "Alice",
"age": 30,
"city": "New York"
}In this example, “name,” “age,” and “city” are the keys, and “Alice,” 30, and “New York” are their corresponding values.
This simple structure allows developers to easily work with data, making JSON a popular choice for many programming tasks.
const jsonString = '{"name": "John Doe", "age": 30, "isStudent": true}';
// JavaScript object
const jsonObject = JSON.parse(jsonString);
console.log(jsonObject);
// Output: { name: 'John Doe', age: 30, isStudent: true }
const backToJsonString = JSON.stringify(jsonObject);
console.log(backToJsonString);
// Output: '{"name":"John Doe","age":30,"isStudent":true}'
// Pretty print JSON
const prettyJsonString = JSON.stringify(jsonObject, null, 2);
console.log(prettyJsonString);





