JSON Basics
JSON, which stands for JavaScript Object Notation, is a syntax for storing and exchanging data. When we exchange data between a web browser and a web server, the data can only be text. That’s why JSON is text, and we can convert any JavaScript object into JSON, and send JSON to the web server.
We can also convert any JSON received from the server into JS objects. This way we can work with the data as JS objects, with no complex parsing and translations. It is a lightweight data-interchange format and is language independent.
Another thing is that JSON can be compared with XML. Both of them can be used to receive data from a web server. They have got some similarities:
- Both JSON and XML are “self-describing”
- Both JSON and XML uses hierarchical structure
- Both JSON and XML can be parsed and used by many languages
- Both JSON and XML can be fetched with an XMLHttpRequest
They have got some dissimilarities as well:
- JSON doesn’t use end tag or element
- JSON is shorter than XML
- JSON is quicker to read and write
- JSON can use arrays
XML has to be parsed with an XML parser. JSON can be parsed by a standard JavaScript function. So, JSON is much more easier to parse than XML. It is also parsed into a ready-to-use JS object.