JSON overview

Connect with

JSON formatJSON data structureis a widely used platform-independent data structure data format to exchange the data between heterogeneous system. JSON format is widely used nowadays by almost all the languages by all the developers whether its web application or enterprise application or database.

1. About JSON format

JSON (JavaScript Object Notation) is simple structured text format for data exchange. JSON is a platform and programming language-independent data format. It is used to handshake the data between two different applications whether its Web Application or enterprise application and storage of data too. JSON is a very popular data format nowadays and used by almost every language extensively. JSON is lightweight in terms of size and parser too.

Why I said it’s lightweight just because of the size of JSON if you compare it from XML. There are a lot of libraries available in the industry, however, you can use proven libraries like Google’s Gson and Jackson parser which is being widely used in the industry nowadays and this is very flexible.

Few of the NoSQL document-based databases like MongoDB use extensively JSON formate as storage and querying too. You can visit my another post if you like to know 13 reasons of using mongoDB. Messaging framework Kafka extensively used JSON in its framework. A lot of JS framework uses JSON format where you can find extensive use of JSON data structure, JS framework as Angular JS, JQuery, etc.

2. Significance of JSON format

JSON is being used to exchange the data between two different system/application. in any RestFul API we write the JSON content as “appplication/json“. Douglas Crokfort came up with the idea of JSON, now used as an international data exchange format.

3. What is the need for JSON data structure ?

Let us understand JSON format in simple terms. Your application architecture is divided into multiple tiers: UI (in Angular ), middle layer in Java, and database in NoSQL MongoDB. In the middle layer, a lot of APIs exposed to different services which the UI layer consumed. In this way, you are saying that your UI and middle layer API layer completely decouple each other. You take data from the database process the data and build a response and throw a JSON which understand by any language whether its java, .net, python, PHP, or something else.

In a nutshell, you can say, JSON is a programming language-independent data format, which can be understood by any programming language. JSON data can be exchanged between two heterogeneous systems. It means, in the client and server model, the client developed in one programming language, and middleware server can be developed in another programming language and the database can be developed in another programming language.

for example: JSON to Java: deserialization or consumption of json in Java programming language is very easy to include your familiar library like Google’s Gson. Java to JSON: serialization or production of json in Java programming language is very easy to include your familiar library like Google’s Gson.

Similarly, across the industry, there is multi tier architecture to and from about JSON format. when different system collaborate each other via common json format, developer or user has wonderful experience of using JSON data format.

4. JSON Data Format

A valid JSON format is as bellow:

  1. a valid JSON document is surrounded by curly braces i.e. “{}”
  2. two key-value pairs are separated by comma i.e. “,”
  3. key-values are separated by colon symbol i.e. “:”
  4. arrays are surrounded by square bracket i.e. “[]”
  5. within the square bracket data can be any one of them as: string, key-value paires, object, nested arrays
  6. there is no limit of nested object one within the another

Sample format of JSON: This is the json fomat which include arrays, object, key-value pairs:

{
 persons: [     
  { 
    "id":1, 
    "name": "Anuj", 
    "age":32 
    "address": {
       "city": "New Delhi", 
       "country": "India"} 
    }  
  ] 
}

5. JSON data type

On high level you can find following JSON data type.

  1. String: its a varchar data type like SQL
  2. Number: it can be integer, double or fraction
  3. Boolean: either true or false
  4. Null: to store null value in perticular node.

6. JSON Structure

On high level, JSON structure can have any one of the following:

  1. Key-Value pairs: its simple data type of key value pairs, in which key is always string and value can be String, number , boolean, null or any another nested object.
  2. Object: Object is surrounded by curly braces and within curly braces simple key-value pairs or another object or array can be.
  3. Arrays: arrays is surrounded by square brakcet i.e. [] , within the square bracke there must be either an object or key-value pairs

Valid JSON document as:

{
"id": 1,
"name": {
  "firstName":"ranjeet", 
  "lastName": "Jha"
   },
 "qualificaiton": ["M.Tech", "MBA"],
 "location": "New Delhi, India",
 "socialContact": [
   {
    "linkedIn": :"https://www.linkedin.com/in/jharanjeet/", 
    "googlePlus": ""
   } ]
}

7. Reference

https://www.json.org/

https://www.w3schools.com/js/js_json_intro.asp

you came here it means you like this post, Happy learning, keep growing and keep sharing.


Connect with

3 thoughts on “JSON overview”

Leave a Reply to Rocky Cancel Reply

Your email address will not be published. Required fields are marked *