Json Schema Validate

Validates a JSON object against a schema.

Version 1

HTTP Request
POST /ado/v1/JsonSchemaValidate

Header

ParameterDescription
Ocp-Apim-Subscription-KeyThe subscription key you received when you purchased a plan.

Request Body

Mandatory

ParameterTypeDescription
schemaobjectThe JSON schema as defined by the global JSON schema standard.
dataobjectA JSON object that is used to validate against the schema.

Examples

There are numerous examples that can be taken from this document:
https://json-schema.org/understanding-json-schema/UnderstandingJSONSchema.pdf

So please feel free to use it as a reference. The examples below are taken from that document but is only one of numerous that could be used to demonstrate the possibilities

Valid JSON
Invalid JSON

Request

{
    "schema": {
        "allOf": [
            {
                "type": "object",
                "properties": {
                    "street_address": {
                        "type": "string"
                    },
                    "city": {
                        "type": "string"
                    },
                    "state": {
                        "type": "string"
                    }
                },
                "required": [
                    "street_address",
                    "city",
                    "state"
                ]
            }
        ],
        "properties": {
            "street_address": true,
            "city": true,
            "state": true,
            "type": {
                "enum": [
                    "residential",
                    "business"
                ]
            }
        },
        "required": [
            "type"
        ],
        "additionalProperties": false
    },
    "data": {
        "street_address": "1600 Pennsylvania Avenue NW",
        "city": "Washington",
        "state": "DC",
        "type": "business"
    }
}
Code language: JSON / JSON with Comments (json)

Response

Given the JSON compared to the schema is valid, an empty array is returned.

[]
Code language: JSON / JSON with Comments (json)

Request

{
    "schema": {
        "allOf": [
            {
                "type": "object",
                "properties": {
                    "street_address": {
                        "type": "string"
                    },
                    "city": {
                        "type": "string"
                    },
                    "state": {
                        "type": "string"
                    }
                },
                "required": [
                    "street_address",
                    "city",
                    "state"
                ]
            }
        ],
        "properties": {
            "street_address": true,
            "city": true,
            "state": true,
            "type": {
                "enum": [
                    "residential",
                    "business"
                ]
            }
        },
        "required": [
            "type"
        ],
        "additionalProperties": false
    },
    "data": {
        "street_address": "1600 Pennsylvania Avenue NW",
        "city": "Washington",
        "state": "DC",
        "type": "business",
        "something that doesn't belong": "hi!"
    }
}
Code language: JSON / JSON with Comments (json)

Response

The order of the given properties is out of step with the defined schema, therefore, an error is returned.

[
    "Property 'something that doesn't belong' has not been defined and the schema does not allow additional properties. Path '['something that doesn\\'t belong']'."
]
Code language: JSON / JSON with Comments (json)