Coding With Fun
Home Docker Django Node.js Articles FAQ

Is parsing json faster than parsing xml?


Asked by Charlee Maxwell on Dec 15, 2021 XML



Average time to parse JSON and get the value using JSON_VALUE() function is around 3 microseconds while the equivalent action with XML typed variable and value() method takes between 30 and 40 microseconds. This shows that parsing JSON "plain text" is 10x faster than parsing strongly typed XML variable. Code
Thereof,
Why JSON is Better Than XML. XML is much more difficult to parse than JSON. JSON is parsed into a ready-to-use JavaScript object. For AJAX applications, JSON is faster and easier than XML: Using XML. Fetch an XML document. Use the XML DOM to loop through the document.
Likewise, JSON's data types also have a 1:1 mapping to data types traditionally considered "primitive" - such as strings, intergal and real numbers, arrays ans key-value tables.
Moreover,
Both JSON and XML can be used to receive data from a web server. The following JSON and XML examples both define an employees object, with an array of 3 employees: XML has to be parsed with an XML parser. JSON can be parsed by a standard JavaScript function. XML is much more difficult to parse than JSON.
In this manner,
An application that uses SAX directly is likely to utilize the information set more efficiently than a DOM "parser" does. StAX is a happy medium where an application gets a more convenient API than SAX's event-driven approach, yet doesn't suffer the inefficiency of creating a complete DOM.