XML
and JSON
are two different content types that are used for the interchange of data between different systems.
JSON is a javascript simple object model that contains key and value types. It is the lightweight data format used in REST API and Microservices. It is easily readable by humans and machines.
JSON simple example
const jsondata = {
"name": "john",
"email":"[email protected]"
}
XML is a start and end tag, and the validation is based on XML Schema. It provides many features, used in Service Oriented Architecture with SOAP Protocols. It is complex to understand humans.
Example xml
<users>
<user id="1">
<name>Eric<name>
<salary>4000</salary>
</user>
</user>
Difference between XML and JSON
XML | JSON |
---|---|
XML contents contains type less data | JSON object c content typed data |
Only Supported type is String | Supports types such as Array, String, Number, and Boolean |
Browser support is limited | It supports all browsers including latest |
It is complex to serialize and deserialize in javascript | Easy to serialize and deserialize in javascript |
Parsing and writing requires parser | Easy to read and write with language |
Format is based on schema | Contains Key a nd value pair |
Language supports popular languages | Supports all programming languages |
Comments are supported | Comments not supported |