Home > Uncategorized > Difference between XML and JSON

Difference between XML and JSON


JSON can be used in web applications for data transfer. Prior to JSON, XML was considered to be the chosen data interchange format. XML parsing required an XML DOM implementation on the client side that would ingest the XML response, and then XPath was used to query the response in order to access and retrieve the data. That made life tedious, as querying for data had to be performed at two levels: f irst on the server side where the data was being queried from a database, and the second time was on the client side using XPath. JSON does not need any specific implementations; the JavaScript engine in the browser handles JSON parsing. XML messages often tend to be heavy and verbose, and take up a lot of bandwidth while sending the data over a network connection. Once the XML message is retrieved, it has to be loaded into memory to parse it; let us take a look at a students data feed in XML and JSON.

The following is an example in XML:

<?xml version=”1.0″ encoding=”utf-8″?>

<students>

<student>

<studentid>101</studentid>

<firstname>Jony</firstname>

<lastname>M</lastname>

<classes>

<class>Computers</class>

<class>Maths</class>

<class>Eng</class>

</classes>

</student>

<student>

<studentid>102</studentid>

<firstname>Den</firstname>

<lastname>g</lastname>

<classes>

<class>Finance</class>

<class>UI</class>

<class>Maths</class>

</classes>

</student>

</students>

Let us take a look at the example in JSON:

/*This is an example students feed in JSON */

{

“students”: { “0”: { “studentid”: “101”, “firstname”: “A1”, “lastname”: “B1”, “classes”: [ “A1”, “b1”, “c1” ] }, “1”: { “studentid”: “102”, “firstname”: “A2”, “lastname”: “B2”, “classes”: [ “A2”, “b2”, “c2” ] } }

}

Advertisements
Categories: Uncategorized
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: