JSON stands for javascript object notation and it is a file that stores and transports data and is filled with strings. It is primarily used to transmit data between an web app and a server. A client/server data exchange for APIs/configs. It is widely used due to lightweight format and it being language independent. JASON uses key/value pairs as well as array, and the key/value pairs are separated by a colon between them with key being on the left side and value being on the right. Key is a string that is surrounded by a double quotation marks and value is a type data. The type of data or value that JSON can have include numbers, strings, booleans, null, objects and arrays.
Example1: { “name”:”bob”, “car”:null, “age”:22, “work”:true } <- separated by commas
Example2: {“codes”: [11, 12]}
String value must always use double quotes. Example1 “name:”bob” is pretty much an example of a string key/value pairs. For numbers, you don’t need double quotes for the value, so you will get “Age”:14. The numbers has to be a integer or floating point number, which is a decimal point value.
Array pretty much means a list, except it is ordered. List cannot manage arithmetic operations but array can. Arrays are enclosed in squared brackets. So [] means an array of object or a list, while {} means it will be an object. Example2 shows an example of an array.
Then we have boolean, which also doesn’t need double quotes for the value. For example, “Marketing”:true is an example of boolean. The value can be either true or false.
Then we have null, which lets you know that it’s not empty, just hasn’t been assigned a value yet. For example, in example1, we can put null instead of a value for the car like true/false (boolean) or model name (strings). We can even put amount of cars using numbers.
JSON format is syntactically similar to javascript objects, so javascript has built in function that can convert JSON strings into javascript objects which is JSON.parse() and its opposite, JSON.stringify(). This is one of the reason why it’s so popular when it comes to web building, due to ease of use and integration.
JSON file is perfect for storing temporary data and is widely used on forms on a website. For example, user identification verification system requires email validation. We can send address data in JSON format to address validation service API. Also, since it is more lightweight compared to XML, it’s more preferred. This is more or less a great data transfer tool.