JSON, which stands for JavaScript Object Notation, is a lightweight data format intended for the storage and transmission of information. It is especially beneficial in web applications that require data transfer from a server to a web page. The structure of JSON facilitates human readability while also ensuring that it can be easily parsed and generated by machines.
JSON data is organized into name/value pairs, similar the way properties are established in JavaScript objects. Each pair comprises a field name (which is enclosed in double quotes), followed by a colon, and subsequently the corresponding value. For instance, "firstName":"Martin" illustrates a name/value pair where “firstName” serves as the key and “Martin” as the value.
'{"name":"Martin", "age":34, "salary":25000}'
It defines an object with 3 properties:
All above properties having value.
JSON Syntax Rules
JSON Object
{"name":"John"}
- Above json object has key - name and value John. - As object it is enclosed in curly braces.
JSON Array
[{"name":"John"},{"name":"Martin"}]
- Above json array has 2 objects. - As array it is enclosed in square braces.
String
Textual data enclosed in double quotes (e.g., "hello")
number
: Numeric data (e.g., 123, 3.14)
boolean
: true or false values
null
: Represents the absence of a value
object
: A collection of key-value pairs enclosed in curly braces {}
array
: An ordered list of values enclosed in square brackets []