JSON vs XML

JSON vs XML

Before JSON became the industry standard, XML was widely used to transfer web data.

Both JSON and XML are human-readable and highly hierarchical data formats.


The Main Differences

JSON is significantly shorter, cleaner, and faster to read and write than XML.

XML requires opening and closing tags for every single piece of data.

JSON does not use end tags, making the file size substantially smaller over network requests.


Why JSON is Better for JavaScript

XML must be parsed using a complex XML DOM parser.

JSON can be parsed directly into a native JavaScript object with one single command.

Furthermore, JSON natively supports arrays, whereas XML does not have a native array format.

JSON vs XML Comparison:

/* The JSON Format (Clean and Compact) */
{"employees":[
  {"firstName":"John", "lastName":"Doe"},
  {"firstName":"Anna", "lastName":"Smith"}
]}

/* The XML Equivalent (Verbose and Heavy) */ <employees> <employee> <firstName>John</firstName> <lastName>Doe</lastName> </employee> <employee> <firstName>Anna</firstName> <lastName>Smith</lastName> </employee> </employees>


SEO and Performance Impact

Search engines evaluate how quickly a browser renders your webpage.

Parsing an XML document creates immense overhead for the browser engine.

Parsing JSON is near-instantaneous, resulting in blazing fast interfaces that search algorithms love to promote!


Exercise 1 of 2

?

Which format natively supports data arrays without using repeating child tags?

Exercise 2 of 2

?

Why is JSON generally faster for web applications than XML?