JSON, or JavaScript Object Notation, is a lightweight data interchange format that is often used when data is being passed between a web application and a server, or between two services. It is easy for humans to read and write, and easy for machines to parse and generate. It is a text format that is completely language independent, but uses conventions that are familiar to programmers of the C-family of languages, such as C, C++, C#, Java, JavaScript, Perl, Python, and many others.

JSON is built on a subset of the JavaScript Programming Language, Standard ECMA-262 3rd Edition - December 1999. JSON is a text format that is completely independent of any programming language. It is used to transmit data between the browser and web servers often in the form of API responses.

Why Use JSON?
JSON is used primarily to transmit data between a server and web application, as an alternative to XML. It's advantages include its simplicity, ease of understanding, and capibility to be read and generated by most modern programming languages.

JSON is a good choice when you're working with agile programming languages that are executed on runtimes, or when you're working within network services architecture to handle, parse, and expose data.
JSON Structures

JSON structures in JavaScript are based on data types such as numbers, strings, objects, arrays, bolleans, and null. These structures define the basis for all JSON data.
JSON data is stored in .json files, and can be sent via AJAX and fetched or accessed from JavaScript. JSON structures can be independently verified and corrected because they are intrinsically tied to their content.
JSON Example

Here is an example of a simple JSON object:
'{ "name":"John", "age":30, "city":"New York" }'
In this example, the data is in key-value pair format. The keys must be strings enclosed in double-quotes, and the values can be any data type, including null.

Working with JSON in JavaScript
In JavaScript, we can use the JSON.parse() method to convert a JSON string into a JavaScript object:




















let text = '{ "name":"John", "age":30, "city":"New York"}'; let obj = JSON.parse(text); console.log(obj.name);
The JSON.stringify() method does the opposite, it converts a JavaScript object into a JSON string:
let obj = { "name":"John", "age":30, "city":"New York"}; let text = JSON.stringify(obj); console.log(text);
Looping Through JSON Objects
We can use JavaScript's for...in loop to loop through all the keys and values of a JSON object:
let obj = { "name":"John", "age":30, "city":"New York"}; for (let x in obj) { console.log(obj[x]); }
Or, alternatively, the Object.keys() method can be used:
for (let i of Object.keys(obj)) { console.log(obj[i]); }
While JSON is a simple concept to grasp, it is a powerful tool that makes data exchange between systems efficient and straightforward. Its wide adoption by the programming community makes it a crucial skill to have in your toolkit. Try out these examples in your own projects and watch your API calls become a breeze!