Table of Contents
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:
1 2 3 4 5 6 7 8 9 10 11 12 13 |
{ "Countries": [ Â Â Â { "Name": "India", Â Â Â "Capital": "Delhi" Â Â Â }, Â Â Â { Â Â Â "Name": "France", Â Â Â "Major": "Paris" Â Â Â }, Â Â Â ] Â Â Â } |
The above sample store informatipn about two countries.Basically
- Squiggly brackets({ }) act as containers
- Square brackets([ ]) represents arrays.
- Names and values are separated by a colon(:).
- 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
Was this post helpful?
Let us know if this post was helpful. Feedbacks are monitored on daily basis. Please do provide feedback as that\'s the only way to improve.