JSON introduction (JavaScript Object nonation)

Source: Internet
Author: User
What is JSON?
JSON (JavaScript Object Notation) is a lightweight data exchange format. Easy to read and write. It is also easy to parse and generate machines. It is based on a subset of JavaScript (Standard ECMA-262 3rd edition-December 1999. JSON uses a completely language-independent text format, but it also uses a habit similar to the C language family (including C, C ++, C #, Java, JavaScript, Perl, Python, and so on ). These features make JSON an ideal data exchange language. JSON structure:
1. A collection of name/value pairs ). In different languages, it is understood as an object, record, struct, dictionary, and hash table ), keyed list or associative array ).
2. An ordered list of values ). In most languages, it is understood as an array ).

These are common data structures. In fact, most modern computer languages support them in some form. This makes it possible to exchange a data format between programming languages that are also based on these structures.JSON format

1. The object is an unordered set of 'name/value' pairs. An object starts with "{" and ends. Each "name" is followed by a ":", and "," is used to separate the "name/value" pairs.
2. An array is an ordered set of values. An array ends with "[" and. Values are separated by commas.
3. values can be string, number, true, false, null, object, or array enclosed by double quotation marks ). These structures can be nested.
4. string is a set of any number of Unicode characters enclosed by double quotation marks, which are escaped in italic. A character (character) is a separate string (characeter string ).

Comparison between JSON and XML

Readability
The readability of JSON and XML is comparable. One side is the suggested syntax and the other side is the standard tag format, which makes it difficult to distinguish between the two.
Scalability
XML is inherently highly scalable, and JSON is also available. There is nothing XML can be extended, and JSON cannot.
Encoding difficulty
XML has rich coding tools, such as dom4j and JDOM, and JSON also provides tools provided by json.org. However, JSON encoding is much easier than XML, JSON code can be written without tools, but it is not easy to write XML.
Decoding difficulty
XML parsing takes into account the parent node of the child node, which is confusing, and the difficulty of JSON Parsing is almost 0. There is nothing to say about XML.
Instance comparison
Both XML and JSON use structured methods to mark data. The following is a simple comparison.
Assume that a user data includes the user name, password, department, gender, and age.
It is represented as follows in XML:
<? XML version = "1.0" encoding = "UTF-8"?>
<User>
<Name> Zhang San </Name>
123456 </password>
<Department> Technical Department </Department>
<Sex> male </sex>
<Old> 30 </old>
</User>
JSON format:
{
"Name": "Zhang San ",
"Password": "123456 ",
"Department": "Technology Department ",
"Sex": "male ",
"Old": "28"
}
Like XML, JSON is also text-based and uses unicode encoding, which is also readable. XML is more suitable for marking documents, while JSON is more suitable for data exchange processing.

JSON Official Website
For more information about JSON, visit its official website: www.json.org
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.