JSON stands for JavaScript Object Notation. It is a format for storing and exchanging data. It is based on a subset of the JavaScript Programming Language.
The file type for JSON files is “.json” and MIME type for JSON text is “application/json“.
Here are the characteristicsof JSON:
It is a lightweight data-interchange format.
It is easy for humans to understand.
It uses Javascript format but it is a text which makes it is completly language independent as text can be read and parsed by any programmng language.
JSON is based on two structures – Objectsand Arrays.
Objects
It is an unordered set of name/value pairs.
An object begins with { (left brace) and ends with } (right brace).
The name value pairs are written as:
“name”:”value”
name is written in double quotes.
Name-value pairs separated by comma
Arrays
It is an ordered collection of values.
An array begins with [ (left bracket) and ends with ] (right bracket).
Values separated by comma.
Values
JSON Values in the Objects and Arrays can be:
string (in double quotes)
Number
Boolean (true or false)
null
object
array
JSON requires double quotes to be used around strings and property names. Single quotes are not valid.
JSON is a string, we need to convert it to javascript native object for accessing the JSON data. This is called parsing.
Converting javascript native object to JSON string is called stringification, you can use the javascript function JSON.stringify() for it.
You can validate JSON using an application like JSONLint.
Parsing JSON
1. JSON.parse()
You can use the javascript function JSON.parse(text) to convert a JSON text into a javascript object.
Leave a Comment