JSON Editor

Knowledge Base

Back to All Topics

JSON vs XML

Both XML and JSON are widely used today. They are used as data interchange formats and both have been adopted by applications as a way to store structured data. 

JSON XML
JSON is simple to read and write. XML is less simple as compared to JSON.
JSON files are more human-readable than XML. XML files are less human readable.
JSON object has a type. XML data is typeless.
JSON types: string, number, array, boolean. All XML data should be string.
Data is readily accessible as JSON objects. XML data needs to be parsed.
JSON is supported by most browsers. Cross-browser XML parsing can be tricky.
JSON has no display capabilities. XML provides a capability to display data because it is a markup language.
Retrieving value is easy. Retrieving value is difficult.
Supported by many Ajax toolkit. Not fully supported by Ajax toolkit.
A fully automated way of deserializing/serializing JavaScript. Developers have to write JavaScript code to serialize/de-serialize from XML.
Native support for object. The object has to be expressed by conventions - mostly missed use of attributes and elements.

 

Why is JSON better than XML

XML is much more difficult to parse than JSON. It has to be parsed with an XML parser.
JSON is parsed into a ready-to-use JavaScript object by a standard JavaScript function.

JSON Example

{
"students":[
      {"firstName":"John","lastName":"Frank"},
      {"firstName":"Bob","lastName":"Jones"},
      {"firstName":"Bill","lastName":"Doe"}
]
}

XML Example

<students>
  <student>
    <firstName>John</firstName> <lastName>Frank</lastName>
  </student>
  <student>
    <firstName>Bob</firstName> <lastName>Jones</lastName>
  </student>
  <student>
    <firstName>Bill</firstName> <lastName>Doe</lastName>
  </student>
</students>

For AJAX applications, JSON is faster and easier than XML.