JSON has eclipsed XML as the preferred data interchange format for web applications and web services. Here’s why
JavaScript Object Notation is a schema-less, text-based representation of structured data that is based on key-value pairs and ordered lists. Although JSON is derived from JavaScript, it is supported either natively or through libraries in most major programming languages. JSON is commonly, but not exclusively, used to exchange information between web clients and web servers.
Over the last 15 years, JSON has become ubiquitous on the web. Today it is the format of choice for almost every publicly available web service, and it is frequently used for private web services as well.
The popularity of JSON has also resulted in native JSON support by many databases. Relational databases like PostgreSQL and MySQL now ship with native support for storing and querying JSON data. NoSQL databases like MongoDB and Neo4j also support JSON, though MongoDB uses a slightly modified, binary version of JSON behind the scenes.
Why should I use JSON?
To understand the usefulness and importance of JSON, we’ll have to understand a bit about the history of interactivity on the web.
In the early 2000s, interactivity on the web began to transform. At the time, the browser served mainly as a dumb client to display information, and the server did all of the hard work to prepare the content for display. When a user clicked on a link or a button in the browser, a request would be sent to the server, the server would prepare the information needed as HTML, and the browser would render the HTML as a new page. This pattern was sluggish and inefficient, requiring the browser to re-render everything on the page even if only a section of the page had changed.
Because full-page reloads were costly, web developers looked to newer technologies to improve the overall user experience. Meanwhile, the capability of making web requests in the background while a page was being shown, which had recently been introduced in Internet Explorer 5, was proving to be a viable approach to loading data incrementally for display. Instead of reloading the entire contents of the page, clicking the refresh button would trigger a web request that would load in the background. When the contents were loaded, the data could be manipulated, saved, and displayed on the page using JavaScript, the universal programming language in browsers.