公用的 schema 描述了 Spread.Sheets JSON 数据格式,这使 Spread.Sheets JSON 格式的数据简单易用,可读性也比较高。也提供了完整的数据验证来验证给出的 JSON 是否合理。
请查看 Spread Schema 来获取完整的 Schema 列表。
如果想了解更多有关 JSON Schema 的信息,请访问 json-schema.org。
JSON Schema 文档可以被用来检查 JSON 数据是否正确。
你也可以通过 JSON Schema 来创建一个正确格式的 JSON 数据。
以下例子演示了如何使用 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 } } } |
想了解更多创建校验器的信息,请访问:http://json-schema.org/implementations.html。
你可以在 https://json-schema-validator.herokuapp.com 在线验证 JSON 数据是否符合 JSON Schema。
你可以使用 Spread.Sheets 中的 JSON Schema 来校验 Spread.Sheets 的 JSON 数据。
请按照以下步骤操作来使用 Spread.Sheets 中的 json-schema-validator 来校验数据:
比如你有两组名叫 "NameInfo" 的 JSON 数据,你想知道这两组数据哪一个是正确的数据。
{ "name":"name1", "row":4, "column":3, "formula":"=SUM(A1,A3)" } |
{ "name":"name1", "row":"4", "column":3, "formula":"=SUM(A1,A3)" } |
NameInfo 的 JSON Schema 如下所示:
{ "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" } } } |
使用 JSON Schema 验证 JSON 数据,就会发现 “jsonData2” 是不正确的。“row” 的类型应该是 “integer”。
一个 JSON schema 引用了另外一个 JSON schema。例如以下 JSON Schema 引用了 "LineStyle" 的 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" } } } |
使用 “LineBorder” 的 JSON Schema 来验证 JSON 数据 “LineBorder”,
{ "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] } } } |