I'm a non-developer and new to JSON and have created a JSON schema to validate JSON code when troubleshooting customer issues to insure syntactics against our defined data elements. I noticed that I can only verify min/maxLength if the field type is an integer. If the type=string, min/maxLength does not work.
JSON Schema code snippet:
"LastName": {
"type" : "string",
"optional": false,
"minLength": 1,
"maxLength": 254,
"description": "Last Name of Insured"
},
In JSON code, if "LastName": "" it still validates, but our WS/JSON call will fail because this field is required and requires data.
Thanks in advance!
It should work per the spec. Reference and quote below. Please elaborate "If the type=string, min/maxLength does not work." - what unexpected exacting behavior do you get?
https://json-schema.org/understanding-json-schema/reference/string.html
Length
The length of a string can be constrained using the minLength and maxLength keywords. For both keywords, the value must be a non-negative number.
{
"type": "string",
"minLength": 2,
"maxLength": 3
}
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