I am trying to validate JSON scheme using TV4.
My validation is using hierarchical JSON and is based on this basic example:
var data = {
"foo": "bar"
};
var schema = {
"type": "object",
"properties": {
"foo": {
"type": "string"
}
},
"required": ["foo"]
};
var result = tv4.validateResult(data, schema);
In my test I want to add one more hierarchy level:
var data = {
"foo": {
"test": "bar"
}
};
var schema = {
"type": "object",
"properties": {
"foo": {
"test": {
"type": "string"
}
}
},
"required": ["foo"]
};
var result = tv4.validateResult(data, schema);
This validation does not work (if I put an integer instead of a string it passes the validation)
What am I doing wrong here?
Disclaimer: I have never used TV4 before.
I'd guess that the schema should specify the foo property as an object with a string property... Something like:
{
"type": "object",
"properties": {
"foo": {
"properties": {
"test": {
"type": "string"
}
},
"type": "object"
}
},
"required": ["foo"]
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With