Json is the abbreviation of JavaScript object symbol. It is a simplified data exchange format and the most commonly used data exchange format among Internet services. It's concise and easy to read.
Common data types in json mainly include
An example of json format is as follows:
As mentioned above, json is a widely used data exchange format. Since it is the format of data exchange, there are two aspects of data exchange. How to agree or verify that the other party's data format meets the requirements has become a problem to be solved in service interaction. So Json Schema is the standard for defining Json data constraints. According to this convention mode, both parties who exchange data can understand the requirements and constraints of json data, and can also verify the data accordingly to ensure the correctness of data exchange.
At present, the latest Json-schema version is draft 7, and the release time is 20 18-03- 19. Let's take official website as an example to see how Json-schema constrains data and its application.
The following is an example of a pattern:
Analysis and explanation:
Description of the currently used schema version, which may not be included.
Unique id identification of the current mode, usually pointing to an autonomous domain name. Subsequent references may not be included.
The title that briefly describes the current mode of information may not include.
Detailed description information, which may not include
The constrained object is the object, that is, the data in {}.
The description of the constraints of specific attributes in an object is descriptive information, and no specific constraints are generated.
Type constraint productid property type is integer.
Restrict the property type of productName to character type.
The constraint price attribute type is a number, which can be an integer or a floating point.
ExclusiveMinimum constraint number >; 0 (excluding 0)
The constraint tag attribute is an array. Items is an array item constraint, in which all constraint array items are of character type.
The minItems array contains at least 1
Each item in the uniqueItems constraint array cannot be repeated.
Constrained dimension nested objects, where length, width and height are all numeric types.
These three fields must be contained in the dimensions object.
The current data object must contain three fields: productId, productName and price.
The above is a simple description of Json-Schema, and the details will be introduced later.