There are so many programming languages, and every language has its own features. But all of them have one thing in common: they process data. From a simple calculator to supercomputers, they all work on data.

It’s the same with humans: there are so many countries, so many cultures, and so much knowledge within each community.

But to communicate with other communities, people need a common medium. Language is to humans what JSON is to programming, a common medium of data transmission.

What is JSON?

JSON stands for JavaScript Object Notation. So before understanding JSON let’s understand objects in JavaScript.

Every programming language has some method of storing similar data together. In C, for example, they are called structures.

In JavaScript, objects are a collection of key-value pairs, where values can be any variable (number, string, boolean), another object, or even a function. Objects are very useful in object-oriented programming.

Object-oriented programming is a programming paradigm based on the concept of “objects”, which can contain data, in the form of fields, and code, in the form of procedures.

Let’s look at an example.

In JavaScript, objects are defined using curly braces, for example:

var obj = {};

Here, obj is an empty object. You can also create objects using constructors, for example:

function Student(name, roll_number, age) {
  this.name = name;
  this.roll_number = roll_number;
  this.age = age;
}

var student1 = new Student("Abhishek", "123", 18);

console.log(student1.name, student1.roll_number, student1.age);

JS objects using constructors

This would give the output Abhishek 123 18.

This is how you create objects in JavaScript. But these objects are still variables that are only specific to JavaScript.

If you want to export these objects, and for example send them to a server, you need a method to encode them. Let’s see how it’s done.

#json #javascript #developer

JSON Stringify Example – How to Parse a JSON Object with JS
1.90 GEEK