JSON comparison XML benefits

Source: Internet
Author: User
Tags php server

1. Definition Introduction

(1). 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 uses the DTD (document type definition) document type definition to organize the data, a unified format, cross-platform and language, and has long been recognized as a standard in the industry.
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.

(2). JSON definition
JSON (JavaScript Object Notation) is a lightweight data interchange format with good readability and easy-to-write features. Data exchange between different platforms is possible. JSON uses a very high compatibility, completely independent of the language text format, but also has a similar to the C language habits (including C, C + +, C #, Java, JavaScript, Perl, Python, etc.) the behavior of the system. These features make JSON an ideal data exchange language.
JSON is based on JavaScript programming Language, Standard ECMA-262 a subset of 3rd Edition-december 1999.

Pros and cons of 2.XML and JSON

(1). Advantages and disadvantages of XML
<1>. Advantages of XML
A. Uniform format, in line with the standards;
B. Easy to interact with other systems remotely, data sharing is more convenient.
<2>. Disadvantages of XML
A.xml file is large, the file format is complex, the transmission occupies the bandwidth;
B. 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;
C. The way the client parses XML between different browsers is inconsistent, and many code needs to be written repeatedly;
D. The server side and client parsing XML spend more resources and time.

(2). The pros and cons of JSON
<1>. The advantages of JSON:
A. Data format is relatively simple, easy to read and write, the format is compressed, occupy small bandwidth;
B. Easy to parse, client-side JavaScript can simply pass the eval () to the JSON data read;
C. Support multiple languages, including ActionScript, C, C #, ColdFusion, Java, JavaScript, Perl, PHP, Python, Ruby and other server-side language, convenient for server-side analysis;
D. In the world of PHP, 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;
E. 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.
<2>. The drawbacks of JSON
A. There is no XML format so popular and happy to use widely, without XML so universal;
The B.json format is now in the initial stage of promotion in Web service.

Comparison of the pros and cons of 3.XML and JSON

(1). Readability.
JSON and XML are basically the same readability of data, JSON and XML are comparable in readability, while the proposed syntax, one side of the canonical label form, XML readability.
(2). Extensibility aspects.
XML is inherently well-extensible, and JSON, of course, has nothing to do with XML extension, not JSON.
(3). Coding difficulty.
XML has a wealth of coding tools, such as dom4j, Jdom, and so on, JSON also has json.org provided tools, but JSON is much easier to encode than XML, even if the use of tools can write JSON code, but to write good XML is not easy.
(4). Decoding difficulty.
Parsing the XML takes into account the child node parent, which makes the person dizzy, and the JSON is almost 0 difficult to parse. This is a little bit of XML output.
(5). degree 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). Analytical means.
JSON and XML also have rich parsing tools.
(7). Data volume aspect.
JSON, with respect to XML, has a small volume of data and is faster to pass.
(8). Data interaction aspects.
The interaction between JSON and JavaScript is more convenient, easier to parse, and better to interact with the data.
(9). Data description aspects.
JSON is less descriptive of the data than XML.
(10). Transmission speed.
JSON is much faster than XML.

4.XML comparison with JSON data format

(1). About lightweight and heavyweight
Lightweight and heavyweight is relative, so what is the weight of XML relative to JSON? should be reflected in the parsing, XML is currently designed in two ways: Dom and SAX.
<1>. Dom
Dom is a data Interchange Format XML as a DOM object, the XML file needs to be read 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 the JSON, Because JSON is built on two structures: Key/value, a set of key-value pairs, an ordered set of values, which can be understood as an array;
<2>. Sax
Sax does not require the entire document to be read into the parsed content can be processed, is a step-resolved 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.
Therefore, the light/weight difference between JSON and XML is that:
JSON only provides a holistic parsing scheme, which only works well when parsing less data, and
XML provides a stepwise resolution scheme for large-scale data that is well suited for processing large amounts of data.

(2). About data format coding and parsing difficulty
<1>: In terms of coding.
Although both XML and JSON have their own coding tools, JSON is much simpler to encode than XML, and it can be written out without tools, but it's a bit difficult to write good XML code, and JSON is text-based, like XML, and they all use Unicode encoding. And it is 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.
<2>: In terms of parsing.
In common Web applications, developers often have trouble parsing XML, whether it is server-side generation or processing of XML, or client parsing XML with JavaScript, often leading to complex code, very low development efficiency.
In fact, for most Web applications, they don't need complex XML to transfer data at all, and XML claims are rarely advantageous in terms of extensibility, and 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.

The readability of the encoding, XML has obvious advantages, after all, human language is closer to such a description structure. JSON reads more like a block of data, which is more puzzling to read. However, the unintelligible language that we read is precisely suitable for machine reading, so the value of "Heilongjiang" can be read by country.provinces[0].name the JSON index.
The encoding of handwriting difficulty, the XML is still comfortable, good read of course is good to write. However, the character JSON written is significantly less. With blank tabulation and line wrapping, JSON is a dense and useful data, and XML contains many duplicate tag characters.

JSON comparison XML benefits

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.