Parameters | XML | JSON |
Abbreviation | Extensible Markup Language | JavaScript Object Notation |
Syntax | It is structured as a tree (tags and nodes) | It is structured as key and value pairs |
Namespace support | It supports namespace. | It does not support namespace. |
Array Support | It does not support an array. | It supports an array. |
Speed | Bulky and slow in parsing, leading to slower data transmission | Very fast as the size of the file is considerably small, faster parsing by the JavaScript engine and hence faster transfer of data |
Security | XML structures are prone to some attacks as external entity expansion and DTD validation are enabled by default. When these are disabled, XML parsers are safer. | JSON parsing is safe almost all the time except if JSONP is used, which can lead to a Cross-Site Request Forgery (CSRF) attack. |
Data Types Support | Supports many complex data types including charts, images, and other non-primitive data types. | JSON supports only strings, numbers, arrays Boolean, and objects. Even objects can only contain primitive types. |
UTF Support | XML supports UTF-8 and UTF-16 encodings. | JSON supports UTF as well as ASCII encodings. |