[]
The public schema describes SpreadJS JSON data format, makes the SpreadJS JSON data clear and useful for human and machine-readable documentation, and also provides complete structural validation which is useful for generating SpreadJS JSON data with code, automated testing, and validation of the JSON data. Refer to SpreadJS Spread Schema for the current and complete schema list.
For more information about JSON Schema, see the json-schema.org
web site.
The JSON Schema document can be used to check whether JSON data is valid. You can also create valid JSON data according to the JSON Schema.
This is a basic example of a JSON Schema:
{
"title": "LineBorder",
"description": "Indicates the color of the border line. Use a known color name or HEX style color value. The default value is black.",
"type": "object",
"properties": {
"color": {
"type": "string",
"default": "black"
},
"style": {
"$ref": "#/definitions/LineStyle",
"default": 0
}
}
}
For information about using a theme to create a validator, refer to this website, http://json-schema.org/implementations.html.
You can use the SpreadJS JSON Schema document to validate the SpreadJS JSON data.
The following steps validate SpreadJS JSON data using the json-schema-validator.
Validate part of the JSON data.
For example, you have 2 JSON data of "NameInfo" and you want to know whether both of them are valid JSON data.
{
"name":"name1",
"row":4,
"column":3,
"formula":"=SUM(A1,A3)"
}
{
"name":"name1",
"row":"4",
"column":3,
"formula":"=SUM(A1,A3)"
}
You can get the JSON Schema document of "NameInfo" as in the following:
{
"title": "NameInfo",
"description": "Represents a custom named expression that can be used by formulas.",
"type": "object",
"properties": {
"name": {
"type": "string"
},
"row": {
"type": "integer",
"minimum": 0
},
"col": {
"type": "integer",
"minimum": 0
},
"formula": {
"type": "string"
},
"comment": {
"type": "string"
}
}
}
Validate the JSON data using the JSON Schema. The "jsonData2" is invalid. The type of its property "row" should be "integer".
A JSON schema references another JSON schema. For example, the following JSON Schema references another JSON Schema "LineStyle".
{
"title" : "LineBorder",
"description" : "Indicates the color of the border line. Use a known color name or HEX style color value. The default value is black.",
"type" : "object",
"properties" : {
"color" : {
"type" : "string",
"default" : "black"
},
"style" : {
"$ref" : "#/definitions/LineStyle",
"default" : "LineStyle.empty"
}
}
}
If you want to validate the JSON data of "LineBorder", use a complete "LineBorder" JSON Schema.
{
"title" : "LineBorder",
"description" : "Indicates the color of the border line. Use a known color name or HEX style color value. The default value is black.",
"type" : "object",
"properties" : {
"color" : {
"type" : "string",
"default" : "black"
},
"style" : {
"$ref" : "#/definitions/LineStyle",
"default" : "LineStyle.empty"
}
},
"definitions":{
"LineStyle":{
"title":"LineStyle",
"description":"Specifies the line drawing style for the border. empty:0,thin:1,medium:2,dashed:3,dotted:4,thick:5,double:6,hair:7,mediumDashed:8,dashDot:9,mediumDashDot:10,dashDotDot:11,mediumDashDotDot:12,slantedDashDot:13.",
"enum":[0,1,2,3,4,5,6,7,8,9,10,11,12,13]
}
}
}
Validate the full JSON data. You can use the full version JSON Schema to validate the SpreadJS full version JSON data.