JSON is a text-based data format that is inspired by JavaScript object literal syntax. It can be used independently from JavaScript, and many programming environments can read (parse) and generate JSON.
It’s useful for transmitting data across a network. But you have to convert it into a native JavaScript object before you can access the data. It is not much of an issue because JavaScript provides a global JSON object that has methods available for converting between the two.
It’s a way to easily and quickly share data between applications and is the most widely used data format for web applications.
JSON was not invented by a single person. It was discovered by a bunch of people, independently of one another. Douglas Crockford, who popularized the term and helped it become mainstream, said he “discovered” the technology rather than invented it.
The AJAX revolution was a curious time. XML was hyped to the skies, but JSON became the thing that made AJAX shine. Crockford was a driving force in its popularization. In 2002, he registered json.org and began blogging about it on his site. After that, he worked for some successful companies in the dotcom era, such as PayPal. His high-profile status helped spread the word about the format.
Next, JSON spread from JavaScript to backend development. It was used in system configs, databases, and back-end languages. Then, as new software platforms developed, Single Page Applications (SPA) and modern mobile/web apps that we know today needed some kind of data interchange. This caused it to explode in popularity.
Today, document-oriented data stores like MongoDB provide an API that works with JSON-like data structures thanks to database administrators who also enjoy its flexibility and ease of programming.
Even the best software engineers need some kind of structure to help them describe and exchange data. Software developers need a way to share data, whether it’s in databases, business logic, user interfaces, or all systems communication. There are many approaches to structuring data for exchange. The two broad camps are binary and text-based data. JSON is a text-based format, so it is readable by both people and machines.
The format is similar to the code for creating JavaScript objects. A JavaScript program can easily convert JSON data into a JavaScript object. Since it’s text only, it can easily be sent between computers and used by any programming language.
On a web page, when you type your username and password into a form, you interact with an object that has two fields: username and password.
Within the curly brackets, you see the properties of an object. An object can be thought of as a “single thing.” Within each object are properties that have names and values, separated by colons. The names of the properties are keys, and the values of the properties are their values. In this case, “username” is a key, and “Bilbo Baggins” is a value.
JSON objects hold primitive values. They can also hold arbitrary complex data structures such as graphs of cyclic objects and objects that reference other objects. In this section, you’ll see how to model these complex structures.
With Nested Objects
The bestfriend property refers to another object, which is defined inline as a JSON literal.
With Object References
Now consider object referencing, where instead of holding a name in the best friend property, we hold a reference to the actual object.
Here, we put the handle to the merry object on the bestfriend property. Then, we can obtain the actual merry object off the pippin object via the bestfriend property. We obtained the name from the merry object with the name property. This is called traversing the object graph, which is done using the dot operator.
With Arrays
Another type of structure is arrays. These look like JavaScript arrays and are denoted with a square bracket
And of course, arrays can be made of other arrays. This creates an endless variety of relations between objects that can be expressed in JSON.
Parsing and generating JSON means reading it and creating it, respectively. JSON.stringify() is the built-in mechanism for JavaScript programs to take an in-memory object representation and turn it into a JSON string. To go in the other direction, take a JSON string and turn it into an in-memory object you use JSON.parse().
In most other languages, it’s necessary to use a third-party library that parses and generates JSON. For example, in Java, there are several popular libraries. One of the most popular is Jackson. It is more complex than doing this in JavaScript, but it offers advanced capabilities such as mapping custom types and dealing with other data formats.
In JavaScript, it is common to send and receive JSON to servers. For example with the built-in fetch() API.
Once you turn JSON into an in-memory data structure, be it JavaScript or another language, you can employ the APIs for manipulating the structure.
JSON is one of the most indispensable technologies in the modern software development world. It’s crucial to JavaScript but is also used as a common language for interaction between a wide range of other technologies. Fortunately, the very thing that makes JSON so useful makes it relatively easy to understand. It is a concise and readable format for representing textual data.
SET UP A DISCOVERY CALL WITH US TODAY AND accelerate your product development process by leveraging our 20+ years of technical experience and our industry-leading capability for quick deployment of teams with the right talents for the job.
Dedicated Team
Augmented Teams
What's the Difference