The common advantage of both is the text representation of the data format, can be cross-platform, cross-system exchange of data .
JSON and XML are comparable in terms of readability and extensibility.
In terms of coding difficulty, JSON is slightly simpler than XML, it is best to write XML with XML Editor, tag nesting and pairing manual input for error prone. Therefore, JSON is better than XML in terms of the maintainability of the code.
As far as content parsing is concerned, JSON can be parsed at the client by using eval (), including ActionScript, C, C #, ColdFusion, Java, JavaScript, Perl, PHP, Python, in the server side, Parsing support for languages such as Ruby is simple, while XML is relatively complex, and it takes a lot of code to parse on both the server side and the client.
In terms of data representation and transmission performance, JSON is significantly simpler than XML, simple in format and less bandwidth-intensive.
As far as security is concerned, because most JavaScript libraries use eval () to parse data, there is a security vulnerability to executing malicious JSON data, and of course you can use a specialized JSON parser to avoid this problem. XML is a bit more secure than that.
[XML]
The benefits of using XML as a transport format:
1. The format is uniform and conforms to the standard.
2. Easy to interact with other systems remotely, data sharing is more convenient
3. Call an existing service that uses XML as a transport.
4. Use XSLT to convert XML dynamically. This is an ideal feature in an enterprise service Bus (ESB) scenario.
Disadvantages:
1. The XML file format file is large, the format is complex, the transmission occupies the bandwidth.
2. Both the server side and the client need to spend a lot of code parsing XML, regardless of the complexity of the server side and client code and the difficult maintenance.
3. Client parsing of XML between different browsers is inconsistent, and many code needs to be written repeatedly.
4. Server side and client parsing XML cost resources and time.
[JSON]
Advantages:
1. The data format is simple, easy to read and write, the format is compressed, occupy small bandwidth, browser parsing fast.
2. It is easy to parse the language, and client-side JavaScript can simply read the JSON data through eval ().
3. Friendly structure, support multiple languages, including ActionScript, C, C #, ColdFusion, Java, JavaScript, Perl, PHP, Python, Ruby and other languages server-side language, easy to server-side resolution.
4. In the PHP world, there are already Php-json and json-php, which facilitates the direct invocation of the PHP serialization program. PHP Server-side objects, arrays, etc. can be directly raw 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, but the completion of the task is not changed, and easy to maintain.
6. Fairly stable, the additional content of JSON will become a superset.
Disadvantages:
1. There is no XML format so popularized and widely used, universality without XML good.
2. The current promotion of JSON format in Web service is also an initial stage.
Json vs XML