SpreadJS Documentation
Using JSON Schema with SpreadJS

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 Spread Schema for the 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 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" : "LineStyle.empty"
        }
    }
}

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 SpreadJS JSON Schema document to validate the SpreadJS JSON data.

The following steps validate SpreadJS 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
            },
            "column" : {
                "type" : "integer",
                "minimum" : 0
            },
            "formula" : {
                "type" : ["string", "null"]
            }
        }
    }
    

    Validate the JSON data using the JSON Schema. The "jsonData2" is invalid. The type of it's property "row" should be "integer", not "number".

    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 SpreadJS full version JSON data.

 

 


Copyright © GrapeCity, inc. All rights reserved.

Send comments on this topic.