Categories: JSON

JSON Vs XML

JSON and XML are the two most common formats for information exchange.

XML is from World Wide Web Consortium(W3C). JSON is introduced by Douglas Crockford.

Although they are not introduced for same purposes, still their more frequent use is information exchange between software applications.

Applications which deal with document handling are using XML (eg: MS Word)

Applications which are more data involved uses JSON (eg: Facebook)

Both XML and JSON are, Open standards on the Web, Human readable and Machine readable.

We cannot completely say one is better than the other, both formats have advantages over the other in specific situations. See the syntax representation of same data in XML and JSON format here

<Blog>
     <Article>
        <Title>JSON vs XML </Title> 
          <Author>Rajeev</Author>
     </Article>
     <Article>
        <Title>Difference Between JSON and XML</Title>
        <Author>Rajeev</Author>
     </Article>
    <Article>
       <Title>XML Vs JSON</Title> 
       <Author>Rajeev</Author>
    </Article>
</Blog>

JSON Syntax

{"
   Blog":
     [
       { "Title":"JSON vs XML", "Author":"Rajeev" },
       { "Title":"Difference Between JSON and XML", "Author":"Rajeev" },
       { "Title":"XML vs JSON", "Author":"Rajeev" }
    ]
}

Major JSON Advantages over XML

JSON is compact and  more readable

JSON can be faster because it is light weighted and less data is transferred.

JSON’s syntax is similar to conventional programming syntax.

XML Advantages over JSON

XML handles metadata information in the better manner, using attributes.

With JSON, the programmer could accomplish the same goal that metadata achieves by making the entity an object and adding the attributes as members of the object.

XML has the ability to resolve name conflicts, prefixes etc. But JSON doesn’t have this power.By having prefixes, the developer can name two different kinds of entities the same thing.This is beneficial in cases where the different entities can have the same name in the client application if their scopes are totally different.

JSON vs XML

See a tabular comparison of difference between JSON and XML format

Attribute/FeatureJSONXML
ObjectivesA text-based format or standard for information interchanging.A markup language having the format that contains a set of rules for
the encoding the documents (schema).
Structure /SchemaLess verbose.Lighter than XML as JSON has serialized format of data having less redundancy. No start and end tags.

No start and end tags.

Heavier format thanJSON, as having a start and an end tags to hold the same data.
PerformanceLightweighted objects, so fasterSlower than JSON
Data TypesJSON supports datatype including integer and strings, and array.

Support for native objects.

No direct support of data types so needs to be parsed into particular
datatype. No direct support for array objects. Support of objects possible through mixed use of attributes &
elements.
CommentsDoes not support commentsSupports comments.
NamespaceNo support for Namespaces.Supports Namespaces.
Data MappingData oriented and can be mapped more easily.Document-oriented and needs more effort for mapping.
ParsingNo need of any additional code for parsing.Needs XML Document Object Model (DOM) implementation along with that additional code for mapping text back to objects.
UsageBetter for Web services.

Facebook, Google Maps use JSON
JSON supported Databses: Oracle,PostgresSQL, MongoDB, CouchDB, eXistDB, Elastisearch, BaseX, MarkLogic, OrientDB, Riak

Better for configuration

MS Word, LibreOffice, Apache OpenOffice etc. uses XML.

XML supported Databases: MS SQL Server, MySQL,DB2,Oracle, PostgresSQL, BaseX, eXistDB, MarkLogic.

Format Changeability JSON data Cannot be changed to another format. Using XSLT you can change XML data into another format like JSON, plain text, CSV,  etc.
AccessibilityNo interface available for getting direct access to a part of JSON data structure.Using XPath, it is possible to get the direct access to data from a particular part of XML
Rajeev

Share
Published by
Rajeev

Recent Posts

OWIN Authentication in .NET Core

OWIN (Open Web Interface for .NET) is an interface between web servers and web applications…

2 years ago

Serializing and Deserializing JSON using Jsonconvertor in C#

JSON (JavaScript Object Notation) is a commonly used data exchange format that facilitates data exchange…

2 years ago

What is CAP Theorem? | What is Brewer’s Theorem?

The CAP theorem is also known as Brewer's theorem. What is CAP Theorem? CAP theorem…

2 years ago

SOLID -Basic Software Design Principles

Some of the Key factors that need to consider while architecting or designing a software…

2 years ago

What is Interface Segregation Principle (ISP) in SOLID Design Principles?

The Interface Segregation Principle (ISP) is one of the SOLID principles of object-oriented design. The…

2 years ago

What is Single Responsibility Principle (SRP) in SOLID Design Priciples?

The Single Responsibility Principle (SRP), also known as the Singularity Principle, is a software design…

2 years ago