JSON - Introduction


What is JSON?

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.


Simple JSON Structure

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.


Simple JSON string/Object example

'{"name":"Martin", "age":34, "salary":25000}'

It defines an object with 3 properties:

  • name
  • age
  • salary

All above properties having value.


JSON Syntax

JSON Syntax Rules

  • Data is organized in pairs of names and values.
  • Commas are used to separate the data.
  • Objects are enclosed within curly braces
  • Arrays are contained within square brackets.

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.


JSON Data types

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 []

Flag Counter