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.
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.
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.
/* 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>
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!
Which format natively supports data arrays without using repeating child tags?
Why is JSON generally faster for web applications than XML?