Reputation: 2845
I've got some Json
{
"store_purchase_control": {
"pass_except_these": [
[
{
"vendor_name_list": {
"value_contains": [
"Amazon",
"Amazon Toys"
]
}
}
]
]
}
}
I'm trying to validate against json schema..
{
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Controls",
"description": "Controls",
"definitions": {
"transaction_amount_limit": {
"type": "integer"
},
"mcc": {
"type": "string",
"pattern": "[0-9][0-9][0-9][0-9]"
},
"val_contains": {
"type": "string"
},
"value_equals": {
"type": "string"
},
"range": {
"type": "object",
"required": ["from", "through"],
"properties": {
"from": {
"$ref": "#/definitions/mcc"
},
"through": {
"$ref": "#/definitions/mcc"
}
}
},
"store_list": {
"type": "array",
"items": {
"$ref": "#/definitions/range"
}
},
"vendor_name_list": {
"type": "array",
"items": {
"$ref": "#/definitions/val_contains"
}
},
"store_id_list": {
"type": "array",
"items": {
"$ref": "#/definitions/value_equals"
}
},
"allow_it": {
"type": "array",
"items": {
"anyOf": [
{"$ref": "#/definitions/vendor_name_list"},
{"$ref": "#/definitions/store_list"},
{"$ref": "#/definitions/store_id_list"}
]
}
},
"always_block": {
"type": "array",
"items": {
"anyOf": [
{"$ref": "#/definitions/vendor_name_list"},
{"$ref": "#/definitions/store_list"},
{"$ref": "#/definitions/store_id_list"}
]
}
},
"pass_except_these": {
"type": "array",
"items": {
"type": "array",
"items": {
"anyOf": [
{"$ref": "#/definitions/vendor_name_list"},
{"$ref": "#/definitions/store_list"},
{"$ref": "#/definitions/store_id_list"}
]
},
"minItems": 1,
"maxItems": 3
}
},
"block_all_except": {
"type": "array",
"items": {
"anyOf": [
{"$ref": "#/definitions/vendor_name_list"},
{"$ref": "#/definitions/store_list"},
{"$ref": "#/definitions/store_id_list"}
]
}
},
"store_purchase_control": {
"type": "object",
"properties": {
"pass_except_these": {"$ref": "#/definitions/pass_except_these"},
"allow_it": {"$ref": "#/definitions/allow_it"},
"always_block": {"$ref": "#/definitions/always_block"}
},
"additionalProperties": false
}
},
"type": "object",
"properties": {
"store_purchase_control": {"$ref": "#/definitions/store_purchase_control"}
},
"additionalProperties": false
}
Parsing this using ..
https://www.jsonschemavalidator.net/
JSON does not match any schemas from 'anyOf'.
Schema path: #/definitions/pass_except_these/items/items/anyOf
Message: Invalid type. Expected Array but got Object. Schema path: #/definitions/store_id_list/type
Message: Invalid type. Expected Array but got Object. Schema path: #/definitions/store_list/type
Message: Invalid type. Expected Array but got Object. Schema path: #/definitions/vendor_name_list/type
It seems to be unable to resolve the anyOf keyword
Upvotes: 0
Views: 685
Reputation: 8428
It's not clear what you're trying to do with this, but it appears that you're trying to add some of the schema constraints to the data.
This is the corrected data that matches the schema:
{
"store_purchase_control": {
"pass_except_these": [
[
[
"Amazon",
"Amazon Toys"
]
]
]
}
}
The pass_except_these
property expects an array of arrays, where each item in the secondary array is one of:
vendor_name_list
which is an array of stringsstore_list
which is an array of range
valuesstore_id_list
which is an array of stringsSo you have an array of arrays, where each item is also an array. You have three levels of arrays.
From the naming of things inside the schema, I expect that this might not be what you're trying to do, but that's the data that satisfies the schema. If you suspect the schema might be wrong, the question is not clear about that.
Upvotes: 1