Let's learn java programming language with easy steps

Saturday, 28 October 2017

What is JSON with Examples

JSON Tutorial

JSON Tutorial - What is JSON?

This JSON tutorial is useful for both beginners and experienced. In this JSON tutorial you will find all the useful examples related to JSON technologies.

Here we will see the definition and simple JSON examples in detail.

What is JSON?

JavaScript object notation(JSON) is a light weight and data-interchange format. JSON objects are used for transferring a data between client and server.

JSON is language independent and it is easy for human to read and write.

JSON supports string, array, objects, number, value.

JSON uses JavaScript syntax but only in text format just like XML.

We can use JSON with other programming language e.g Java, Python, C#, C++, Perl, JavaScript, Ajax, JQuery, Ruby, etc.

JSON is text and we can convert any JavaScript object into JSON and send JSON to the server.

History of JSON

JSON technology was invented by Douglas Crockford. 

JSON is an alternative of an XML. 

JSON is simple and easy to learn in comparison of XML.

Syntax of JSON

  • JSON allows to write a data in key and value pairs.
  • JSON uses commas(":") to separate the data.
  • JSON uses curly("{") braces to store objects.
  • JSON uses square bracket( "[") to store the array.

Let's take simple look of JSON data

{"name":"anurag", "address":"f13"},
{"name":"anurag", "address":"g43"}

JSON final must be save with .json extension.

JSON data types

Some data types are supported by JSON technology which are given below.
  • String
  • Array
  • Boolean
  • Value
  • Object
  • Number
  • Whitespace
  • null

We can create JSON example with the help of objects and arrays. Let's create examples of JSON one-by-one with objects and arrays.

(1) JSON Object Examples

This is the simple json object example. Here we will use curly braces and  key & value pairs to represents json object where keys are string and values are json types and use comma to separate the data.

     "student": {
     "name" : "sunny", 
     "roll no" : 56,
     "monitor" true

In the above example, "student" is an object and "name", "roll no" and monitor is a key with string, number and boolean type values for the keys.

Each object can have different - different data such as text, number, boolean, etc. 

JSON Object Example with String

To represents string values we use double quotes("").

    "student": {
    "name" : "karan",  "address": "anand vihar"

JSON Object Example with Number

   "student" : {
   "Integer" : 56,
   "fraction" : 1.23

JSON Object Example with boolean

    "student" : {

    "weak" : false,

    "strong" : true

Nested JSON Object Example

    "student" : {
    "name" : "anu",
    "rollo no" : 45,
   "address" : {
   "city" : "delhi",
   "pincode" : "65"

(2) JSON Array Examples

JSON array can contains multiple and it can contains number, string, boolean, and objects in an JSON array.

We have to use square bracket [ to represents json array and for separation of values use comma.

JSON Array Example of String, Number, and Boolean

Json array string example:

["red", "blue", "black", "pink"]

Json array number example:

[2, 4, 1, 5]

Json array boolean example

[true, false]

JSON Array of Objects Example

    "students" : [
    {"name" : "raj", "email" : "raj@33", "roll no" : 10},
    {"name" : "numan", "email" : "numan@66", "roll no" : 15},
    {"name" : "ravi", "email" : "ravi@11", "roll no" : 125}

this is json array object example with 4 objects.

XML Example

XML representation of above example.

/* Start */

  <roll no>10</roll no>



  <roll no>15</roll no>


  <roll no>125</roll no>

/* End */

finally, we have learned what is json , json array object example, json object example.


1 comment:

  1. I found best article.thank you for sharing useful info.
    web programming tutorial


Facebook Page Likes

Follow javatutorial95 on Google+

Follow javatutorial95 on twitter

Popular Posts

Get Updates By Email