How to validate an enum value in a json schema validation?
12,322
Your JSON Schema is missing certain attributes. Look at the example provided here on how to start the schema http://json-schema.org/example1.html.
Update your schema to the below and try
{
"type": "object",
"properties": {
"transactions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["BREAK"]
}
},
"required": ["type"]
}
}
}
}
Related videos on Youtube
Author by
sebachili
Updated on June 04, 2022Comments
-
sebachili almost 2 years
the main problem resides on validate a json against a schema that deals with arrays. So, if I put a different value seems to be still valid?
json schema:
{ "transactions" : { "type" : "array", "items" : { "type" : "object", "properties" : { "type" : { "type" : "string", "enum" : ["BREAK"] }, "required":["type"] }, "required":["items"] } } }
Input JSON:
{ "transactions":[ { "type":"BREAKDDDDDdddddddddddddddddddddddddddJDJDJDJDJDJDJDJ" } ] }
result: No errors found. JSON validates against the schema.
This is wrong as we haven't defined an enum type like "BREAKDDDDD"
http://www.jsonschemavalidator.net/
Any thoughts on this?