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.
JSON is constructed in two structures:
(1) A collection of "name/value" pairs (A collection of name/value pairs). In different languages, it is understood as objects (object), record (record), structure (struct), Dictionary (dictionary), hash table (hash table), keyed list (keyed list), or associative array (associative Array).
(2) An ordered list of values (an ordered list of values). In most languages, it is understood as an array (array).
The JSON has these forms:
1. Objects
An object is an unordered collection of "name/value pairs". An object starts with "{" (opening parenthesis) and "}" (the closing parenthesis) ends. Each "name" is followed by a ":" (colon); "' Name/value ' pair ' is separated by", "(comma).
2. Arrays
An array is an ordered collection of values (value). An array begins with "[" (the left square bracket), and "]" (the right square bracket) ends. Use "," (comma) to separate values.
The value (value) can be a string enclosed in double quotation marks (string), a numeric value (number), True, false, NULL, an object, or an array. These structures can be nested.
A string is a collection of any number of Unicode characters surrounded by double quotation marks, escaped with a backslash. A character (character) is a separate string (character string).
A string is very similar to a C or Java string.
The value (number) is also very similar to the value of C or Java. Removes octal and hexadecimal formats that have not been used. Remove some coding details.
Usage examples and Precautions
1. Each property of the object must have double quotation marks, otherwise the JSON data will not load properly
We write a Python script to do the next test:
Import Jsonwith Open ("data.json"'r') as Load_f: Data=json.load (load_f) print(data)
(1) {"name": "Taoeyhuang", "Age": 18}
(2) {"Name": "Taoeyhuang", "age": +, "sex": "Male", Hair: "BLACK"} Here the hair attribute has no double quotes
Exception Log "Json.decoder.JSONDecodeError:Expecting property name enclosed in double quotes:line 1 column (char 43)"
We can also see that the cause of the anomaly is the double quote problem.
2. Multi-object Example (array + object)
Array can be nested arrays or nested objects
{ "name":"Bejson", "URL":"http://www.bejson.com", "page": the, "Isnonprofit":true, "Address": { "Street":"Science Park Road.", " City":"Suzhou, Jiangsu", "Country":"China" }, "links": [ { "name":"Google", "URL":"http://www.google.com" }, { "name":"Baidu", "URL":"http://www.baidu.com" }, { "name":"SoSo", "URL":"http://www.SoSo.com" } ]}
Reference blog:http://www.json.org/json-zh.html
JSON file format detailed