Spread.Sheets Documentation
Using JSON Schema with Spread.Sheets
Spread.Sheets Documentation > Developer's Guide > Managing Data > Using JSON Schema with Spread.Sheets

The public schema describes Spread.Sheets JSON data format, makes the Spread.Sheets JSON data clear and useful for human and machine-readable documentation, and also provides complete structural validation which is useful for generating Spread.Sheets JSON data with code, automated testing, and validation of the JSON data. Refer to Spread.Sheets Spread Schema for the current, complete schema list. Refer to Spread Schema for the schema list for the previous version of Spread.

For more information about JSON Schema, see the json-schema.org web site.

The JSON Schema document can be used to check whether a JSON data is valid. You can also create a valid JSON data according to the JSON Schema.

This is a basic example of a JSON Schema:

Schema
Copy Code
{
      "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 web site, http://json-schema.org/implementations.html. This site, https://json-schema-validator.herokuapp.com, has online validators you can use to check your JSON data based on the JSON Schema document.

You can use the Spread.Sheets JSON Schema document to validate the Spread.Sheets JSON data.

The following steps validate Spread.Sheets JSON data using the json-schema-validator.

  1. Validate part of the JSON data.

    a. For example, you have 2 JSON data of "NameInfo" and you want to know whether both of them are valid JSON data.

    jsonData1
    Copy Code
    {
        "name":"name1",
        "row":4,
        "column":3,
        "formula":"=SUM(A1,A3)"
    }
    
    jsonData2
    Copy Code
    {
    "name":"name1",
        "row":"4",
        "column":3,
        "formula":"=SUM(A1,A3)"
    }
    

    You can get the JSON Schema document of "NameInfo" as in the following:

    NameInfo_JSONSchema
    Copy Code
    {
          "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".

    b. A JSON schema references another JSON schema. For example, the following JSON Schema references another JSON Schema "LineStyle".

    LineBorder
    Copy Code
    {
        "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.

    LineBorder_Complete
    Copy Code
     {
        "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]
            }
        }
    }
    
  2. Validate the full JSON data. You can use the full version JSON Schema to validate the Spread.Sheets full version JSON data.