Java

What is JSON

Jun 11, 2020

What is JSON

JSON stands for JavaScript Object Notation.

Official definition/ explanation for JSON is given as

"JSON (JavaScript Object Notation) is a lightweight data-interchange format. It is easy for humans to read and write. It is easy for machines to parse and generate. It is based on a subset of the JavaScript Programming Language. JSON is a text format that is completely language independent but uses conventions that are familiar to programmers of the C-family of languages, including C, C++, C#, Java, JavaScript, Perl, Python, and many others. These properties make JSON an ideal data-interchange language."

Based upon the discussion, I would like it to relate that JSON is one of the most used data interchange language, for example if you want a Microservice built in Java to talk with another Microservice built in Node.JS, they can connect with each other using JSON.

JSON is a mediator language like your expression, no matter if you speak English, French, German, Arabic or Japanese the thing is if you are smiling you are happy and if you are crying you are sad. Irrespective of your language, anywhere in the world any one can detect if you are sad or happy.

"So in simple words JSON are the expression in the world of programming languages"

How does JSON looks like?

A JSON Object is a combination of name value pairs which are separated by a colon (:) and engulfed inside a pair of curly braces {} .

A name in key value pair is always a String, but a value can be of possible types.

  • STRING,
  • NUMBER,
  • BOOLEAN,
  • OBJECT,
  • ARRAY ,
  • NULL.

 

 

1. Simple JSON Object

{
    "name":"Sachin Tendulkar",
    "country":"India",
    "centuries" :100
}

Above described is a simple JSON Object only containing the key value pairs.

2. JSON Object with another JSON Object inside it.

{
    "empId":1000,
    "name":"Tom",
    "dept":"IT",
    "project":{
                "name":"Big Data Analysis of Covid Data",
                "manager":"Alex"
              },
    "salary":34098.88

}

Above described is a simple JSON Object containing another JSON Object by name of project inside it.

3. JSONObject with Array and an Object inside it.

{
     "firstName": "John", "lastName": "Smith", "age": 25,
     "address" : {
         "streetAddress": "21 2nd Street",
         "city": "New York",
         "state": "NY",
         "postalCode": "10021"
     },
     "phoneNumber": [
         { "type": "home", "number": "212 555-1234" },
         { "type": "fax", "number": "646 555-4567" }
     ]
}

In the example JSON above, we can see that a JSON Object is encompassed inside a pair of curly braces and it contain

  • a String Value in form of firstName

  • a JSON Object in form of address (which further contains another key value pairs inside it)

  • an array in form of phoneNumber.

Related Posts

Table Of Contents

;