Coding With Fun
Home Docker Django Node.js Articles Python pip guide FAQ Policy

JSON vs. XML


May 08, 2021 JSON


Table of contents


JSON vs. XML

XML: Extended Markup Language (Extensible Markup Language, XML), which is used to mark electronic files so that they have a structural markup language that can be used to tag data, define data types, and is a source language that allows users to define their own tag language.

JavaScript Object Notation is a lightweight text data exchange format with good readability and easy-to-write features that allow data exchange between different platforms.

Both JSON and XML are human-readable formats and language-independent. I n a real-world environment, they all support creation, reading, and decoding. We can compare JSON and XML by:

Redundancy

XML files are large, the file format is complex, the transmission takes up bandwidth, JSON data format is relatively simple, easy to read and write, the format is compressed, the bandwidth is small.

XML is redundant than JSON, so it's faster for us to write JSON.

Array usage

XML is used to describe structured data that does not contain arrays, while JSON contains arrays.

Analytical

JSON can be resolved using JavaScript's eval method. When this method is applied to JSON, eval returns the object described.

Example

Here's an example of XML and JSON, respectively:

Json:

{
    "company": Volkswagen,
    "name": "Vento",
    "price": 800000
}

Xml:

<car>
   <company>Volkswagen</company>
   <name>Vento</name>
   <price>800000</price>
</car>

Related tutorials

For more information about XML, please refer to the XML tutorial