JSON Introduction
JSON is one of the most used Data-Exchange formats. It is a lightweight format represented as pure text. Due to the ability of almost all the languages to parse text. Json becomes independent of the programming language.
Overview Of Json
JSON stands for JavaScript Object Notation. It human and machine-readable format to represent data as Structured Data. JSON used to transfer data from one computer to different programs on the computer.
Key Value Pairs
Key-Value pairs in JSON used to represent a property of the Object. In the above example, we tried to represent a Person. Key-Value in JSON we have to follow these rules
- Key value pairs separated by a : (colon)
- Key is always present in Double Quotes " "
- Value could be anything about the Data Type
Values can be of following data types
- Boolean: True or False
- Number: Numerical values
- Object: An associative array of Key-Value pairs
- Array: Associative array of values
Object in JSON
In JSON an object represented the collection of Key-Value pairs. This collection of Key-Value pairs grouped using (opening and closing curly braces}. Rules to writing an Object are
- Key-Value pairs separated by a, (Comma)
- Each Object should Start with an Opening (Opening Curly Brace)
- Each Object should End with a Closing (Closing Curly Brace)
Array in JSON
Arrays are like Arrays that you know from any other programming language. In JSON an Array is the collection of Values separated by Comma. Here are the rules to write an Array
- An Array starts with an opening [ (Bracket)
- An Array ends with a closing ] (Bracket)
- Values in the Array separated by, (Comma)
To understand an Array let us add one more property to the Person Object. Let us add hobby also, a Person can have many hobbies. This makes it suitable to represent hobbies as an Array.
Components of a JSON
See how many hobbies represented using an Array. Array starts and ends with [ ] and contains values separated by, These are the various components of a JSON, using these components we can create complex JSON.