Difference between JSON and XML
Prerequisite:
JSON (JavaScript Object Notation) is a lightweight data-interchange format and it completely language independent. It is based on the JavaScript programming language and easy to understand and generate.
Example :
{"Geeks":[ { "firstName":"Vivek", "lastName":"Kothari" }, { "firstName":"Suraj", "lastName":"Kumar" }, { "firstName":"John", "lastName":"Smith" }, { "firstName":"Peter", "lastName":"Gregory" } ]} |
XML (Extensible markup language) was designed to carry data, not to display data. It is a W3C recommendation. Extensible Markup Language (XML) is a markup language that defines a set of rules for encoding documents in a format that is both human-readable and machine-readable. The design goals of XML focus on simplicity, generality, and usability across the Internet. It is a textual data format with strong support via Unicode for different human languages. Although the design of XML focuses on documents, the language is widely used for the representation of arbitrary data structures such as those used in web services.
Example :
<Geeks> <Geek> <firstName>Vivek</firstName> <lastName>Kothari</lastName> </Geek> <Geek> <firstName>Suraj</firstName> <lastName>Kumar</lastName> </Geek> <Geek> <firstName>John</firstName> <lastName>Smith</lastName> </Geek> <Geek> <firstName>Peter</firstName> <lastName>Gregory</lastName> </Geek> </Geeks> |
Both of these are self-describing and can be parsed and used by lots of programming languages.
Below are few differences between JSON and XML:
JSON | XML |
---|---|
It is JavaScript Object Notation | It is Extensible markup language |
It is based on JavaScript language. | It is derived from SGML. |
It is a way of representing objects. | It is a markup language and uses tag structure to represent data items. |
It does not provides any support for namespaces. | It supports namespaces. |
It supports array. | It doesn’t supports array. |
Its files are very easy to read as compared to XML. | Its documents are comparatively difficult to read and interpret. |
It doesn’t use end tag. | It has start and end tags. |
It is less secured. | It is more secured than JSON. |
It doesn’t supports comments. | It supports comments. |
It supports only UTF-8 encoding. | It supports various encoding. |
Recommended Posts:
- JSON | modify an array value of a JSON object
- Javascript | JSON PHP
- JSON web token | JWT
- JavaScript JSON
- JSON Formatting in Python
- JavaScript | JSON Arrays
- JSON | Data Types
- Python | Sort JSON by value
- How to receive JSON POST with PHP
- Interesting facts about JSON
- How to parse JSON in Java
- JavaScript | JSON HTML
- JavaScript | JSON.stringify() with Examples
- JavaScript | Remove a JSON attribute
- Working With JSON Data in Python
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.