JSON 是普遍使用的数据交换格式(The JSON Data Interchange Standard)。
JSON (JavaScript Object Notation)
JSON is a lightweight data-interchange format.
value
A value can be a string in double quotes, or a number, or true or false or null, or an object or an array. These structures can be nested.
- null
- boolean
A "true" or "false" value. - object
An object is an unordered set of name/value pairs. - array
An array is an ordered collection of values. An array begins with [ (left bracket) and ends with ] (right bracket). Values are separated by , (comma). - number
An arbitrary-precision, base-10 decimal number value.
"integer" matches any number with a zero fractional part. - string
a sequence of zero or more Unicode characters. Strings are delimited with double-quotation marks and support a backslash escaping syntax.
JSON Schema
- describes your existing data format.
- clear, human- and machine-readable documentation.
- complete structural validation, useful for:
1)automated testing.
2)validating client-submitted data.
JSON Schema Validation
- JSON Schema Validation: A Vocabulary for Structural Validation of JSON.
-
Latest JSON Schema Validation
JSON Schema Validation defines the validation keywords of JSON Schema. - Validation Keywords
比如:required、properties 就是 Validation Keywords for Objects. - JSON Schema Example
{
"$schema": "http://json-schema.org/schema#",
"title": "Product",
"type": "object",
"required": ["id", "name", "price"],
"properties": {
"id": {
"type": "number",
"description": "Product identifier"
},
"name": {
"type": "string",
"description": "Name of the product"
},
"price": {
"type": "number",
"minimum": 0
},
"tags": {
"type": "array",
"items": {
"type": "string"
}
},
"stock": {
"type": "object",
"properties": {
"warehouse": {
"type": "number"
},
"retail": {
"type": "number"
}
}
}
}
}
JSON Editor Online
在线查看 json 格式文件。