Comparison of the pros and cons of JSON and XML

Source: Internet
Author: User
Tags php server

Comparison of the advantages and disadvantages of JSON and XML 1, JSON definition (JavaScript Object Notation)
A lightweight data interchange format with good readability and easy-to-write features. Data exchange between different platforms is possible. JSON uses a high-compatibility text format, and also has a similar behavior to the C language system.
2. XML definition
The Extensible Markup Language (extensible Markup Language, XML), which is used to tag electronic files with a structured markup language that can be used to tag data, define data types, is a source language that allows users to define their own markup language. XML is a subset of standard Generalized Markup Language (SGML) and is ideal for Web transport. XML provides a unified approach to describing and exchanging structured data that is independent of the application or vendor.
3. Comparison of the advantages and disadvantages of JSON and XML (1) Advantages and disadvantages of "xml"
Advantages:
(1) Uniform format, in line with the standard;
(2) Easy to interact with other systems remotely, data transmission is more convenient.
Disadvantages:
(1) The XML file is large, the file format is complex, the transmission occupies the bandwidth;
(2) Both the server side and the client need to spend a lot of code to parse the XML, causing the server and client code to become unusually complex and difficult to maintain;
(3) The client is inconsistent in parsing XML between different browsers, and needs to write a lot of code repeatedly;
(4) The server side and client parsing XML spend more resources and time.
So in addition to the XML format, there is also a JSON
(2) Advantages and disadvantages of "JSON"
Advantages:
(1) Data format is relatively simple, easy to read and write, the format is compressed, occupy a small bandwidth;
(2) Easy to parse, client-side JavaScript can be easily read through Eval_r () JSON data;
(3) Support multiple languages, including ActionScript, C, C #, ColdFusion, Java, JavaScript, Perl, PHP, Python, Ruby and other server-side language, easy to server-side analysis;
(4) In the PHP world, there are already Php-json and json-php appear, partial to the PHP serialization of the program directly call, PHP server-side objects, arrays, etc. can be directly generated JSON format, convenient for client access extraction;
(5) because the JSON format can be used directly for server-side code, greatly simplifies the server-side and client code development, and the completion of the task is not changed, and easy to maintain.
Disadvantages:
(1) There is no XML format so popularized and widely used, no XML so universal;
(2) JSON format is currently promoted in the Web service is also the primary stage
(3) Comparison of the advantages and disadvantages of "XML" and "JSON": (1) in terms of readability, the data readability of JSON and XML is basically the same. JSON and XML are comparable in readability, with the suggested syntax on one side and the canonical label form on the other, which makes it difficult to distinguish between the winners and losers.
(2) In terms of extensibility, XML is inherently well-extensible, JSON of course, there is no XML can be extended, JSON can not.
(3) In terms of coding difficulty, XML has a wealth of coding tools, such as dom4j, Jdom, and so on, JSON also has json.org provided tools, but the JSON encoding is much easier than XML, even if the use of tools can write JSON code, but to write good XML is not easy.
(4) In the decoding difficulty aspect, the parsing of XML takes the child node parent node, makes the person dizzy, but the JSON parsing difficulty is almost 0. This is a little bit of XML output.
(5) In terms of popularity, XML has been widely used in the industry, and JSON has only just begun, but in the specific area of Ajax, the future development must be XML to be located in JSON. Ajax should become Ajaj (asynchronous Javascript and JSON).
(6) JSON and XML also have rich analytic means.
(7) JSON is a small volume of data relative to XML.
(8) The interaction between JSON and JavaScript is more convenient.
(9) JSON is less descriptive of the data than XML.
JSON is much faster than XML.
4. Data Interchange Format comparison of XML and JSON:
"XML" Extensible Markup Language, an HTML-like language that has no pre-defined tags, uses a DTD (document type definition) to organize the data using the file type definitions, uniform format, cross-platform and language, has long been recognized as a standard in the industry. Specifically, you can ask Google or Baidu. In contrast to this lightweight data interchange format of JSON, XML can be called Heavyweight.
The "JSON" JavaScript Object Notation is a lightweight data interchange format. Easy for people to read and write. It is also easy for machine parsing and generation. It is based on JavaScript programming Language, Standard ECMA-262 a subset of 3rd Edition-december 1999. JSON takes a completely language-independent text format, but also uses a similar idiom to the C language family (c, C + +, C #, Java, JavaScript, Perl, Python, etc.). These features make JSON an ideal data exchange language.
5. Data Interchange Format for comparison of lightweight and heavyweight:
Lightweight and heavyweight are relative, so what is the weight of XML relative to JSON? I think it should be reflected in the analysis, XML is currently designed two kinds of parsing methods: Dom and SAX;
Dom is a data Interchange Format XML as a DOM object, you need to read the entire XML file into memory, which is the same as the principle of JSON and XML, but the XML to consider the parent node and child nodes, which is much less difficult to parse JSON, Because JSON is built on two structures: Key/value, a set of key-value pairs, an ordered set of values that can be understood as an array;
Sax does not require the entire document to be read into the parsed content can be processed, is a stepwise analysis of the method. The program can also terminate parsing at any time. In this way, a large document can be gradually and 1.1 points, so sax is suitable for large-scale parsing. At this point, JSON is not available at this time.
So, the difference between the light/weight of JSON and XML is that JSON only provides a holistic parsing scheme, which only works well when parsing less data, and XML provides a step-up solution to large-scale data that is well suited for processing large amounts of data.
6, Data Interchange Format comparison of data format encoding and resolution of the difficulty:
In encoding, although XML and JSON have their own coding tools, but JSON encoding is simpler than XML, even if the use of tools, you can write JSON code, but to write good XML code is a bit difficult; As with XML, JSON is text-based, And they all use Unicode encoding, and they are as readable as the data Interchange Format XML.
Subjectively, JSON is clearer and less redundant. The JSON Web site provides a strict description of the JSON syntax, just a short description. In general, XML is more appropriate for tagging documents, while JSON is more suitable for data interchange processing.
In the analytic, in the common Web application domain, the developer often has the nerve to parse the XML, whether the server side generates or processes the XML, or the client uses the JavaScript parsing XML, often causes the complex code, extremely low development efficiency.
In fact, for most Web applications, they do not need complex XML to transmit data at all, and XML claims that extensibility is rarely an advantage; many AJAX applications even return HTML fragments directly to build dynamic Web pages. Returning HTML fragments greatly reduces the complexity of the system compared to returning XML and parsing it, but at the same time lacks some flexibility. The Data Interchange Format JSON provides greater simplicity and flexibility than XML or HTML fragments. In Web Serivice applications, at least for now, XML still has an unshakable position. Transfer from http://blog.sina.cn/dpool/blog/s/blog_8a30865f0101amjh.html

Comparison of the pros and cons of JSON and XML

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.