What is JSON?



I have a friend who’s had a really hard time wrapping his head around JSON because he’s never worked with it, and even though we’ve studied Computer Science together, programming hasn’t been his strongest suit.
No matter how hard I tried explaining what it is with words, in the end, he still thinks it’s some complicated language of mystery that only the pros know. Here’s my take at explaining JSON for the layman:


— The Concept of JSON —
Imagine the country Norway wanting to send some important piece of information to the country Spain. Now, how do they go about doing this?
Norway could send the message in Norwegian and let Spain find a person who knows both Norwegian AND Spanish and is able to translate from one language to the other.
Or Norway could find someone who knows both Norwegian AND Spanish, and first translate the message from Norwegian to Spanish, and then send it over.
In either case, we need someone who knows both of the languages.
If Norway and Spain want to send messages back and forth to each other, both of them need someone who knows both of the languages.
Isn’t that making things a bit too complicated? What if we could make things simpler by incorporating a new language that both understand? That would certainly make things simpler, right?
Enter the lingua franca, English. If both Norway and Spain instead use the English language to send their messages back and forth, neither of them would need to know Spanish or Norwegian. It’s just one common language used to understand each other.
However, for the sake of understanding, let’s say English is only the language for communication between the countries. When Norway receives a message in English from Spain, they would still need to translate it to Norwegian — because of reasons!
Likewise, if Spain were to receive a message in English from Norway, they would still have to translate it into Spanish too, let’s say.. uhh.. to further work with their laws which are specifically in Spanish! (play along with me here)
But, why then learn English if they’re anyway going to translate it back to their native language?
Imagine that Norway and Spain don’t only send a message to each other, but also communicate with France, Pakistan, Switzerland, and Russia. All those countries have their own languages. Having to know and translate to all those languages would be pretty difficult, don’t you think?
Instead, each country knows English in addition to their own language. Then, any country can send a message to another country in English, and then the receiving country can translate from English to their own language. There’s now one universal language for communication!
That’s the idea of JSON. Instead of understanding how any of the programming languages work, there is a common “language” solely used for communication.
If for example PHP and Javascript want to send each other information, they don’t need both have learned PHP AND Javascript and translate back and forth in order to communicate. Instead, they use the “lingua franca” of communication in programming, JSON, to send each other messages. These messages can then be translated from JSON into their respective language.
You are now able to learn only one programming language, in addition to the communications language, JSON, in order to communicate with ANY other programming language.
But hold on a second, you might’ve heard people say that JSON is NOT a programming language. And that is correct, it is NOT!
Although the analogy with the countries works well with explaining WHAT JSON is, it fails at explaining HOW JSON works. After all, English is a “complicated” language that takes a lot of time to learn. The JSON “language” is very simple and easy to learn. So, let’s make another analogy for the JSON “language” and its “grammar”.

— How JSON Works —
Now, let’s forget communication between countries for a second.
Imagine your boss at your new job wants you to write him a report on all the new cars in 2017.
You take on the task with all your might in hopes to make a great list of all the new cars in 2017!
Here is what you give to your boss:
Text Source: Car - Wikipedia
Now then, I don’t think he’d be too pleased with it even though you put in a lot of effort gathering the information. But you gave him exactly what he asked for, right? Yes, you did a fine job.
The problem is that your boss wants to put the list of cars into his online scrapbook, and if putting all the cars and information in there wasn’t enough work already, he now also has to actually readunderstand and get an overview of all the cars and their corresponding information from your wall of text. Heck, even reading and understanding that report alone is so off-putting!
You are slightly disheartened by this, considering your efforts. However, you refuse to yield and decide to give your report another go.
This time you turn in this organized report:
It’s got a Table of Contents, colored sections, and a nice format which makes the information super easy to find and read. You go and hand the report to your boss.
Your boss wants to find the new Batmobile model, so he opens the Table of Contents, which looks like this:
Okay, so apparently the Batmobile is located on page 3, your boss thinks. He proceeds to turn to page 3. What he finds is something similar to this:
There’s a clear title for the page, and this page is divided into three headers. Everything has a good structure so finding the information is seamless and super easy! All the other cars have a similar page with the same structure. Your boss can turn to any page in the cars section and expect it to have the same structure with a description, the color, and an image.
Your boss LOVES it! He is now able to easily “translate” this structured information onto his online scrapbook. Good job, you get a raise!
A few months later, he asks you for the same thing — a report on new cars in 2017, but this time with the car model as well. You compile a new report, which largely contains the same cars as last time, but since then there have been released a few new cars in the market. You hand him the new report with the list of the cars, in the same format and structure as last time, but with a new header added for all the cars — the model.
The Batmobile page now looks like this:
And it continues like this as long as you have the job, because your boss asks for a list of new cars every 3 months for his scrapbook, and you always deliver with this nice format.
Now, which one of the two formats of the report that you handed to your boss turned out to be the best? Well, obviously the last one. No human could possibly read the first jumbled wall of text!
Let’s say the way you formatted your post was so great that you had to turn it into a design language — a format of structure/organization of text that everyone should follow when making reports, in order to make the recipient understand the text in the best way possible, and also perhaps use the information for their own personal gains (e.g. online scrapbooks).
You call this new standard way of formatting for JSON. You write a list of rules that people who want to use this format need to adhere to.
Now, whenever your boss asks for a new report, he says “Give me a list of all new bikes in 2017, in JSON format, please.”. When he asks for the information in JSON format, you immediately know that you need to have a Table of Contents, sections, pages and headers, all formatted in a specific way according to the rules you specified.
JSON suddenly becomes popular and is used as a standard format for communication between employees and their boss.
Now, back to the real world and the real JSON. Computers also need structure, and just as we humans have a hard time reading the first block of text without structure, so do computers. The nicely organized report book you made is similar to what JSON is for computers.

— Understanding JSON —
Combining the two analogies above, we have any two parties that want to communicate with each other. They speak different languages but want to send each other messages. For that, they use a common standardized language that both understands — English. They can just throw random words at each other, but that would make no sense or would be too difficult to understand. They need structure. So, they use grammar, which is a format, to understand each other quickly.
That format, that way of organizing the message to send, that both parties know regardless of whatever programming language or system they themselves use, is called JSON.
Last example. Let’s say PHP and Javascript want to send each other messages. In theory, they can send each other a big wall of unorganized text, but they would have to send each other Manuals on how to actually read the text. You would have to write PHP code specifically for that piece of text in order to interpret it into PHP code. The same goes for Javascript. If only there were common rules that everyone used.
JSON provides a certain way of organizing/formatting the message to send, and since it’s so popular, almost all programming languages either have built-in JSON interpreters or libraries to convert the JSON-formatted text into the respective programming language so that it can understand it and use it.
Honestly, the JSON format looks a lot like a Table of Contents, except that instead of page numbers, the corresponding information is directly available under a section.
For example, take the Table of Contents we had earlier of the cars. If we instead put all of the information in there like this:
It basically is almost in JSON format. There are 3 levels of indent, and each indent is under the header that is above it. JSON works in the same way and relies of levels when you want to extract the information.
The equivalent Table of Contents above in JSON format would look like this (only showing the three topmost cars — click image to zoom):
That’s basically it, the list of cars we want to convey in JSON format.


JSON is like wrapping your text message in a nice gift box and sending it so that anyone can open it and get the message.

Thanks.
Next Post Previous Post
No Comment
Add Comment
comment url