In the programming world, JSON is a popular data format to exchange information. What’s cool about this is, every programing language has agreed to support JSON format. Let’s say calling a movie database to find all the info about a specific movie.

Jason Voorhees

The server will return the movie data in this looking format:

{
"Title": "Friday the 13th",
"Year": "2009",
"Rated": "R",
"Released": "13 Feb 2009",
"Runtime": "97 min",
"Genre": "Horror, Mystery, Thriller",
"Director": "Marcus Nispel"
}

JSON is actually a JavaScript Object Notation. It’s invented by this cool guy:

Douglas Crockford

So let’s talk about JavaScript objects first.

You probably know about different types of variables like:

String name = "Taylor Swift";
int age = 100;
boolean isAwesome = true;

These are what we call primitive values that programming languages give you to start off. But what if you need a more complex set of custom data types?

For this we have objects.

I have heard so many explanations from many developers and teachers about what classes and objects are. But I figure out, they are nothing more than just a custom data type.

A is a custom data type I created that has a name, age, hasKilled, and birthday information:

class Person {
String name;
int age;
boolean hasKilled;
String birthday
}

And this is how it will look like in JavaScript (JS has no types):

var jason = {
name : "Jason Voorhees",
age : 74,
hasKilled : true,
birthday: "June 13, 1946"
}

Okay, so that works well but the problem comes when sending this data over the internet to another application.

Enter JSON!

JSON is similar to JavaScript objects but here all the properties and values are enclosed in double-quotes. This makes them a string of text that can be sent across the internet:

{
"name":"Jason Voorhees",
"age":74,
"hasKilled":true,
"birthday":"June 13, 1946"
}

That’s just the start of JSON formatting. You can have objects inside these JSON objects:

{
"name":"Jason Voorhees",
"age":74,
"hasKilled":true,
"birthday":"June 13, 1946",
"info": {
"weapon": "Machete",
"location": "Camp Crystal Lake",
"classification": "Mass Murderer"
}
}

You can even have lists or arrays:

{
"name":"Jason Voorhees",
"age":74,
"hasKilled":true,
"birthday":"June 13, 1946",
"info": {
"weapon": "Machete",
"location": "Camp Crystal Lake",
"classification": "Mass Murderer"
},
"victims": ["Barry", "Claudette", "Bill", "Brenda"]
}

Now you can convert any object to JSON and vice versa.

In JavaScript, there is a global class JSON that has two methods for making and decoding them:

Converts a standard object into JSONable text.

Does the opposite by taking a JSON string and outputting a JS object.

In Python there is a json package to do these things:

loads the JSON text into an object.

converts the python object into JSON text.

There are such methods or packages in every top programming language since JSON is universal.

After you convert your object to a JSON string, it will be a piece of text like this:

Now you have your data to send over the internet!

Question: What other data formats out there?

Other than JSON, there are BSON, XML, YAML, binary, etc...

I hope you enjoyed this post. Do give it a clap if you do.

Software Engineer, Full-Stack developer, MERN Stack. (Open for hire) https://tamalweb.com/blog

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store