Let's learn java programming language with easy steps. This Java tutorial provides you complete knowledge about java technology.

Showing posts with label JSON Tutorial. Show all posts
Showing posts with label JSON Tutorial. Show all posts

Monday, 30 October 2017

Difference Between JSON and XML

JSON vs XML

What is the Difference Between JSON and XML

Here we are going to discuss the difference between JSON and XML with simple examples. In the last post, We have discussed some examples of json technology i.e what is JSON but here we will see JSON vs XML comparison.

Let's start, What is the difference between JSON and XML and what is the advantages of JSON over XML.


JSON

  • JSON stands for JavaScript Object Notation.
  • JSON is easy to learn in comparison to XML.
  • JSON  is easy to read and write.
  • JSON does not use any opening(<>) and closing(</>) tags. 
  • JSON is data-oriented technology.
  • JSON is less secured than XML.
  • JSON is light-weight in comparison of XML.
  • JSON supports arrays.
  • JSON supports text and number data types.
  • JSON is less verbose than XML so it is faster to write programs in json.


JSON Example

This is simple example of json where will take student data with the help of json's object and array.

{"students" : [
    {"name" : "shiv", "section"  : "A", "city" : "delhi"},
    {"name" : "john", "section"  : "B", "city" : "mumbai"},
    {"name" : "varun", "section" : "C", "city" : "keral"}
]
}

Now moving to XML


XML

  • XML stand for eXtensible Markup Language.
  • XML is not easy to learn in comparison of JSON.
  • XML is less easy to read and write than JSON.
  • XML uses opening(<>) and closing(</>) tags to define data.
  • XML is documented-oriented technology.
  • XML is more secured than JSON.
  • XML is not light-weight than JSON.
  • XML does not support arrays.
  • XML supports text, number, chart, images, data types.
  • XML is more verbose than JSON, so it is not faster to write programs than JSON.

XML Example

This is a simple example of XML where we will define some data of students in XML format. Let's convert above JSON example to XML.

For example:

<students>
  <student>
    <name>shiv</name>
    <section>A</section>
    <city>delhi</city>
  </student>
<student>
    <name>john</name>
    <section>B</section>
    <city>mumbai</city>
</student>
<student>
    <name>varun</name>
    <section>C</section>
    <city>keral</city>
</student>
</students>

This was the differences between json and xml. Now let's discuss some similarities between JSON and XML.


Similarities Between JSON and XML

There are some similarities between json and xml and these are given below.
  • JSON and XML both are open and simple technology.
  • JSON and XML both are language - independent.
  • JSON and XML both are self - describing i.e human readable.
  • Internationalization is supported by JSON and XML because of both support unicode system.

Share:

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

{"students":[
{"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 */

<students>
 <student>
  <name>raj</name>
  <email>raj@33</email>
  <roll no>10</roll no>
</student>

<student>

  <name>naman</name>

  <email>naman@66</email>
  <roll no>15</roll no>
</student>
<student>

  <name>ravi</name>

  <email>ravi@11</email>
  <roll no>125</roll no>
</student>
</students>

/* End */

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

Share:

Facebook Page Likes

Follow javatutorial95 on twitter

Popular Posts

Translate