tadasajon
tadasajon

Reputation: 14864

Why is this json schema invalid? using "any" type

{
    "$schema": "http://json-schema.org/draft-04/schema#",
    "title": "my json api",
    "description": "my json api",
    "type": "object",
    "properties": {
        "my_api_response": {
           "type": "object",
            "properties": {
                "MailboxInfo": {
                    "type": "array",
                    "items": {
                        "type": "object",
                        "properties": {
                            "ADSyncLinkEnabled": {
                                "type": "any"
                            }
                        }
                    }
                }
            }
        }
    },
    "required": ["response"]
}

I am using python jsonschema 2.0.0 and it gives me the following error:

{u'type': u'object', u'properties': {u'ADSyncLinkEnabled': {u'type': u'any'}}} is not valid under any of the given schemas

Upvotes: 32

Views: 29991

Answers (2)

Reinsbrain
Reinsbrain

Reputation: 2591

From json-schema.org documentation, we find this regarding "type" property:

If it is an array, it must be an array of strings, where each string is the name of one of the basic types, and each element is unique. In this case, the JSON snippet is valid if it matches any of the given types.

So, another way to achieve a sort of "any" type, you might include all json types:

"type":["number","string","boolean","object","array", "null"]

Upvotes: 15

fge
fge

Reputation: 121820

This is because any is no longer a valid value for the type keyword.

If you want a schema which matches everything, just use the empty schema: {}.

Upvotes: 59

Related Questions