JavaScript JSON
JS
JSON, or JavaScript Object Notation, is a lightweight data-interchange format. It's a way to organize and transport data that's easy for humans to read and write, and easy for machines to parse and generate. Despite its name, JSON is language-independent and is used by many programming languages, not just JavaScript.
What is JSON?
- JSON stands for JavaScript Object Notation.
- It is a lightweight data format used to store and exchange data.
- It is easy for humans to read and write, and easy for machines to parse and generate.
It is often used to send data between a client (browser) and a server.
JSON Syntax
JSON is written in key-value pairs inside .
- Keys are always strings (enclosed in double quotes " ").
- Values can be: string, number, object, array, boolean, or null.
JSON in JavaScript
JSON is very similar to JavaScript objects, but there are differences:
- JSON keys must be in double quotes.
- JSON does not support functions or comments.
Converting between JSON and JavaScript objects
1️. JSON to JavaScript Object
Use JSON.parse() to convert JSON string → JavaScript object.
2️. JavaScript Object to JSON
Use JSON.stringify() to convert JavaScript object → JSON string.