What is JSON

Ravithamara Wijayabandu
2 min readMay 31, 2021

JSON stands for JavaScript Object Notation. It is an open standard data interchange and file format. It was first invented by Douglas Crockford. It is a generic, lightweight, self-describing, human readable, language independent format that uses for storing and transporting data. Since it stores data in object pattern, it easy to read and write. Although it is language independent, actually it was derived from JavaScript language. It is supported by many development environments. JSON file is basically a text file with extension .json.

Mostly it uses when web applications communicate with a server. Common use is read data from server and display in web page. We can send JSON to the server and convert JSON received from server into JavaScript objects. JSON can include basic data types as Number, String, Boolean, Array, Object, Null values etc. JSON objects can not have data types like function, date, undefined etc.

This example defines an object called “employee”

{
“employees”:[
{“firstName”:”John”, “lastName”:”Doe”},
{“firstName”:”Anna”, “lastName”:”Smith”},
{“firstName”:”Peter”, “lastName”:”Jones”}
]
}

In this format data is stored in key value pairs. Key value pair consists field name and value in double quotes. Key and value separated by colon. Data is separated by commas. Objects are written in Curly braces. Square brackets hold arrays. Every misplaced colon or comma can produce errors.

This example defines an object called “menu” and as we mentioned before “menuItem” is a example for array data type

{“menu”: {

“id”: “file”,

“value”: “File”,

“popup”: {

“menuitem”: [

{“value”: “New”, “onclick”: “CreateDoc()”},

{“value”: “Open”, “onclick”: “OpenDoc()”},

{“value”: “Save”, “onclick”: “SaveDoc()”}

]

}

}}

This helps convert JSON data into JavaScript objects. JavaScript use JSON.parse() in built method to convert string into JavaScript object

var obj = JSON.parse(text);

we use JSON.stringfy() method to convert JavaScript object into a JSON

var myObj = {name: “John”, age: 31, city: “New York”};
var myJSON = JSON.stringify(myObj);
window.location = “demo_json.php?x=” + myJSON;

there can be nested JSON object as well

myObj = {
“name”:”John”,
“age”:30,
“cars”: {
“car1”:”Ford”,
“car2”:”BMW”,
“car3”:”Fiat”
}
}

JSON is somewhat like XML. But there are few differences.

>XML uses end tag and JSON does not

>JSON is much shorter than XML and quicker to read, write than XML

>JSON can use arrays and XML does not

>XML has to be parsed with XML parser.

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

No responses yet

Write a response