Java JSON tutorial

In this post,We will see introduction to JSON

Java JSON Tutorial Content:

    JSON Introduction JSON.simple example-read and write JSON GSON example-read and write JSON Jackson example – read and write JSON Jackson Streaming API - read and write JSON

What is JSON?

JSON stands for JavaScript Object Notation.It  is a simple and easy to read and write data exchange format just like XML.JSON is smaller than XML, and faster and easier to parse.

It is entirely language independent and can be used with most of the modern programming languages.

Internet media type of JSON is "application/json".

JSON sample:
    {
    "Countries": [
    { "Name": "India",
    "Capital": "Delhi"
    },
    {
    "Name": "France",
    "Major": "Paris"
    },
    ]
    } 
The above sample store informatipn about two countries.Basically
  1. Squiggly brackets({ }) act as containers
  2. Square brackets([ ]) represents arrays.
  3. Names and values are separated by a colon(:).
  4. Array elements are separated by commas

Comparison with XML:

As JSON and XML both are data exchange format.There is always comparison between them.

Similarity:
  • Both are human readable.
  • Both are hierarchical. (i.e. You can have values within values.)
  • Both are used by most of programming languages.
Differences:
  • JSON is less verbose so it's definitely quicker for humans to write, and probably quicker for us to read.
  • JSON stores data in form of Key-value pair which is universal in nature.
  • JSON is faster than XML.
  • JSON can be parsed trivially using the eval() procedure in JavaScript

Written by Arpit:

If you have read the post and liked it. Please connect with me on Facebook | Twitter | Google Plus

 

Java tutorial for beginners Copyright © 2012