What is JSON?

JSON or JavaScript Object Notation is how computers across the Internet talk. Simply put it’s the medium of communication. Like we humans speak English, computers over the Internet speak JSON.

How do I write it?

Well, it’s not so hard. It’s basically plain text as that is the easiest mode to communicate. Below is sample of what JSON looks like –

{
"name": "Rohan Kumar"
}

If you are familiar with JavaScript, then you will know this is basically an Object. It has a set of curly braces, a key .i.e. “name” and a value. i.e. “Rohan Kumar”. And that is it. The simplest JSON. Well actually the simplest JSON would be {} but you get the point.

So a JSON is basically a set of key/value pairs. The keys have to be in strings always. However, the values can have any of the following values – string, number, object, array, true, false, null. Here is sample of how those will look –

{
"name": "Erik Dennings", // string
"age": 25, // number
"address": 
{
"flat": "123A",
"street": "New Town"
}, // Object
"hobbies":["dancing", "eating"], // Array
"isAlive": true,
"isDead": false,
"children": null // null 
}

Note, null is used when you want to show missing values. Maybe you don’t have that value now, but you will have some in the future.

In JavaScript

It has in built functions which help in easy conversion. For e.g.

const plainText = '{"name":"Rohan"}';
const object = JSON.parse(plainText);
const oldPlainText = JSON.stringify(object);

Similarly every language has it’s own share of helper methods to do the above conversion.

History

JSON made it’s way into the industry in the early 2000s when Douglas Crockford discovered it. Although he is not the one who invented it, he has played a significant role in popularising it. JSON made it’s the way quickly in replacing the old way of communication by XML. It was later standardized in 2013.

Uses

  1. JSON is being used in client-server communications.
  2. It’s a lightweight text-based format.
  3. Since it’s text, any device or programming language can understand it.
  4. Really easy to understand.
  5. Easy to convert to SQL, CSV, and vice-versa.

For more information visit json.org.



Categories: What is

Tags: ,

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.

%d bloggers like this: