Difference between XML and JSON

Key Difference: XML stands for Extensible Markup Language. It can be considered as a simplified version of the Standard Generalized Markup Language. It is a text based markup language and a World Wide Web Consortium standard that allows one to create his or her own tags. JSON stands for JavaScript Object Notation. It is a lightweight open standard for data exchange. It has been designed for human-readable data. Numbers, Booleans, strings, null, array, objects, etc. can be represented by using JSON. XML and JSON differ in many aspects like verbosity, data types, tool stack, etc.

XML stands for Extensible Markup Language. It can be considered as a simplified version of the Standard Generalized Markup Language. It is a text-based markup language and a World Wide Web Consortium standard that allows one to create his or her own tags. It has been widely popular as it has simplified the business to business type of transactions on the web. Due to its advantages, it is on its way for becoming the standard for data exchange on the web. The tags in XML are quite different from HTML, as XML tags recognize the data rather than focusing on the way to display it.

XML content is contained inside tags. Tags consist of content and the description of the enclosed entity. An XML document consists of a prolog and a body. Prolog contains an XML declaration which is possibly followed by a declaration of the document type. The body comprises of a single root element and may also contain some comments and some instructions for processing.

Example:

<branches>

      <branch>

        <department>Computer Science</department>

        <name>software engineering</name>

      </branch>

      <branch>

        <department>Mathematics</department>

        <name>statistics</name>

      </branch>

    </branches>

JSON stands for JavaScript Object Notation. It is a lightweight open standard for data exchange. It has been designed for human-readable data. Numbers, Booleans, strings, null, array, objects, etc. can be represented by using JSON. Basically, JSON has been based on the object notation of JavaScript.

It is a format that is completely independent of languages, however convections similar to the C family of languages are used in JSON. It has been based on two structures –

  • A collection of name and value pairs.
  • An ordered list of values.

Example

 {

      "branch": [

        {

          "department": "Computer Science",

          "name": "software engineering"

        },

        {

          "department": "Mathematics",

          "name": "statistics"

        }

      ]

    }

These days, JSON and XML are seen as competitors. Both have their own set of advantages and disadvantages. JSON syntax needs fewer characters, and thus can be considered as lighter on the wire. However, most of the files are exchanged in a compressed manner, therefore this point of difference does not matter a lot. XML is often preferred as it is capable of getting direct access to a part of multiple parts of an XML data structure. It is important to note that no such interface is present in JSON. For a format change, XML provides easier ways to accomplish the task. However, in JSON there is not an easy way to do the same. JSON is considered to be more efficient as the data is represented as a JavaScript object, and thus few bits are passed through a wire. Less machine time is required for the processing of the data. In a nutshell, JSON is a better data exchange format, whereas XML is a better document exchange format.

Comparison between JSON and XML:

 

JSON

XML

Full Form

JavaScript Object Notation

Extensible Markup Language

Definition

It is a lightweight open standard for data exchange. It has been designed for human-readable data. Numbers, Booleans, strings, null, array, objects, etc. can be represented by using JSON.

It can be considered as a simplified version of the Standard Generalized Markup Language. It is a text based markup language and a World Wide Web Consortium standard that allows one to create his or her own tags.

Verbosity

Less

More

Array usage

Included

Not included

Format

Data interchange

Markup language

Developer

Specified by Douglas Crockford

World Wide Web Consortium

Data types

Scalar data types, structure data can be expressed using arrays and objects

Dependency on XML schema for adding type information

Namespaces

No option to define namespaces

Available

Identifiers

It allows any string as a identifier

It has a restrictive approach

Formatting decision

Simple

Complex

Learning

Easy to learn for developers with familiarity to JavaScript  or dynamic programming languages

Require knowledge of XPath, XML Schema, XML namespaces and similar other technologies

Encoding

Support only UTF-8 encoding

Support different encodings

Tool Stack

Not very rich

Mature (including schema languages, XSLT, and XQuery)

Image Coutesy: invalidxmlfix.com, alsacreations.com

Most Searched in Pregnancy and Parenting Most Searched in Electronics
Most Searched in Education and References Most Searched in Cars and Transportation
Rat vs Mouse
Alcatel One Touch Idol Ultra vs Nokia Lumia 720
Post vs Page
Rajya Sabha vs Vidhan Sabha vs Lok Sabha

Add new comment

Plain text

CAPTCHA
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.