JavaScript JSON
JSON (JavaScript Object Notation) is a lightweight data interchange format inspired by JavaScript object literal syntax.
It is commonly used for transmitting data between a server and a web application, as well as for storing and exchanging data in various applications and platforms.
Data types in JSON
- Objects: Enclosed in curly braces {}, consisting of key-value pairs separated by commas.
- Arrays: Ordered lists of values enclosed in square brackets [].
- Strings: Enclosed in double quotes " ".
- Numbers: Integers or floating-point numbers.
- Boolean values: true or false.
- Null: Represents an empty value.
JSON Objects
JSON objects are written inside curly braces.
Just like in JavaScript, objects can contain multiple name/value pairs:
JSON Arrays
JSON arrays are written inside square brackets.
Just like in JavaScript, an array can contain objects:
Converting a JSON Text to a JavaScript Object
A common use of JSON is to read data from a web server, and display the data in a web page.
For simplicity, this can be demonstrated using a string as input. Just like in JavaScript, an array can contain objects: