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/Feature | JSON | XML |
---|---|---|
Objectives | A 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 /Schema | Less 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. |
Performance | Lightweighted objects, so faster | Slower than JSON |
Data Types | JSON 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. |
Comments | Does not support comments | Supports comments. |
Namespace | No support for Namespaces. | Supports Namespaces. |
Data Mapping | Data oriented and can be mapped more easily. | Document-oriented and needs more effort for mapping. |
Parsing | No 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. |
Usage | Better for Web services.
Facebook, Google Maps use JSON | 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. |
Accessibility | No 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 |
Leave a Reply