Skip to content

JSON Schema Validation

Alexey Valikov edited this page Aug 30, 2015 · 6 revisions

JSON Schema Validation

If you use Jsonix Schema Compiler to compile your schemas, you may also generate an accompanying JSON Schema. See JSON Schema Generation for more information on this feature.

What you basically need to do is just add the -generateJsonSchema command-line option when calling Jsonix Schema Compiler.

As the result, Jsonix Schema Compiler will produce MySchema.jsonschema files which are JSON Schemas matching your MySchema.js Jsonix mappings.

Below is an example of the generated JSON Schema:

{
    "id":"#",
    "definitions":{
        "PurchaseOrderType":{
            "type":"object",
            "title":"PurchaseOrderType",
            "properties":{
                "shipTo":{
                    "title":"shipTo",
                    "allOf":[
                        {
                            "$ref":"#/definitions/USAddress"
                        }
                    ], ...
                },
                "billTo":{
                    "title":"billTo",
                    "allOf":[
                        {
                            "$ref":"#/definitions/USAddress"
                        }
                    ], ...
                },
                "comment":{
                    "title":"comment",
                    "allOf":[
                        {
                            "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/string"
                        }
                    ], ...
                }, ...
            }, ...
        },
        "USAddress":{ ... },
        "Items":{ ... },
        "Items.Item":{ ... },
    },
    "anyOf":[
        {
            "type":"object",
            "properties":{
                "name":{
                    "$ref":"http://www.jsonix.org/jsonschemas/w3c/2001/XMLSchema.jsonschema#/definitions/QName"
                },
                "value":{
                    "$ref":"#/definitions/PurchaseOrderType"
                }
            },
            "elementName":{
                "localPart":"purchaseOrder",
                "namespaceURI":""
            }
        }, ...
    ]
}
Clone this wiki locally