JSON (JavaScript Object Notation) is one of the most popular and widely accepted data exchange
format.
- JSON is widely accepted in the softwares that includes client-server architecture for exchanging data between client and server.
- JSON is easy to use and purely text-based, lightweight, and human- readable format and people often misunderstand as replacement of XML.
- Although the abbreviation starts with JavaScript, JSON is not a language or have any language literals it just a specification for notation of data.
- It is platform and language independent and inbuilt supported by almost all of the front line languages/frameworks like and support for the JSON data format is available in all the popular languages, some of which are C#, PHP, Java, C++, Python, Ruby and many more.
- The official Internet media type for JSON is application/json.
- The JSON file name extension is .json.
JSON Syntax Rules
JSON (JavaScript Object Notation) syntax is based on a subset of JavaScript (see also json.org).
A valid JSON expression can be one of the following data types
- simple data types: String, Number, Boolean, Null
- composite data types: Value, Object, Array
- Simple data types
A JSON string has to be enclosed in double quotes and may contain zero or more Unicode
characters; backslash escapes are allowed. Accepted JSON numbers are in E notation. Boolean
is one of true, false. Null is the reserved keyword null.
Composite data types
Value
A JSON Value can be one of: String, Number, Boolean, Null, Object, Array.
Object
A JSON Object is an comma-separated unordered collection of name:value pairs enclosed in curly
brackets where name is a String and value a JSON value.
Array
A JSON Array is an ordered collection of JSON values.
Example of a JSON array:
[“home”, “wooden”]
Examples of JSON objects:
{
“id”: 1,
“name”: “A wooden door”,
“price”: 12.50,
“tags”: [“home”, “wooden”]
}
[
1,
2,
[3, 4, 5, 6],
{
“id”: 1,
“name”: “A wooden door”,
“price”: 12.50,
“tags”: [“home”, “wooden”]
}
]