Introduction to JSON
- Introduction to JSON
- JSON syntax
- Parsing and Generating JSON files
- JSON data storage application
So let us start with the introduction part.
JSON (Javascript Object Notation) is a lightweight data-interchange format.
Why use it
What is JSON?
- Same syntax as JavaScript objects.
- Easy for humans to read and write.
- Language independent.
- It can be used to store application data.
How can we create /read JSON file?
- JavaScriptSerializer (inbuilt in dotnet framework).
- JSON.NET third party tool (download from Nuget Package Manager).
So let us look at JSON:
{ } culry braces represent object
key – value pair
JSON Syntax
So what exactly makes up a JSON file:
- Values
- Objects
- Arrays
- Putting it all together
JSON Values can be
- Strings ( in double quotes)
- Numbers (integer or floating point)
- Boolean ( true or false )
- Objects ( in curly brackets)
- Array( in square brackets)
- Null
JSON Object
- Name/value pairs using colons
- Enclose by curly braces
- Pairs separated by commas
Example
- {
- name: values,
- name2: values2
- }
So here is a very simple example curly braces representing json object, name values pair separated by comma:
- {
- "Name" :"Ravi",
- "City": "Varanasi",
- }
More complex example
- {
- "countryId": 1,
- "countryName" : "India",
- "state" : ["uttar pradesh","Mumbai","Bangalore"]
- }
JSON Arrays
- Values enclosed by brackets
- Separated by commas [item,item,item,item]
Example
["uttar pradesh","Mumbai","Bangalore"]
Indicated by bracket we have JSON arrays and in this example its an array of three string and each string separated by commas:
[1,2,3,4] its array of number
Complex array
- [
- {
- "AlbumId": 3,
- "GenreId": 1,
- "ArtistId": 4,
- },
- {
- "AlbumId": 5,
- "GenreId": 1,
- "ArtistId": 77,
- }]
- JSON values can also be objects or arrays
- JSON objects and arrays can be nested

Points of Interest
- In this article, I have touched the very basics of JSON.
- JSON is very useful in client-server communication where network bandwidth is very limited.


Rashmita ShresthaPosted Apr 10, 2017, 10:45 PM EDT
Very informative...
Asfend YarPosted Mar 6, 2016, 9:06 AM EST
nice
Ravi PatelPosted Dec 10, 2015, 8:16 PM EST
Thanks Neelam
Neelam PrajapatiPosted Dec 10, 2015, 8:01 PM EST
good one
Ravi PatelPosted Oct 25, 2015, 7:38 AM EDT
thanks!
Santhakumar MunuswamyPosted Oct 25, 2015, 7:11 AM EDT
Good one
Ravi PatelPosted Oct 25, 2015, 4:08 AM EDT
thanks!
Gowtham KTOP 100Posted Oct 24, 2015, 11:08 PM EDT
Good One
NitinPosted Oct 24, 2015, 10:14 PM EDT
Nice
Rupesh KahanePosted Oct 24, 2015, 10:28 AM EDT
Great ...
Ravi PatelPosted Oct 24, 2015, 9:40 AM EDT
thanks Mukesh for appreciation
Mukesh KumarPosted Oct 24, 2015, 9:00 AM EDT
Good Job
Ravi PatelPosted Oct 24, 2015, 8:58 AM EDT
thanks Nilesh
Nilesh JadavPosted Oct 24, 2015, 8:44 AM EDT
Good Share sir !