I need to implement schema validation for incoming JSON payload.
The below elements will be there in the JSON,
"partyId": {
"type": ["string","null"],
"maxLength": 16,
"required": false,
"description": "Party ID"
},
"erpId": {
"type": ["string","null"],
"maxLength": 20,
"required": false,
"description": "ERP ID"
}
Required validation : Any one element should be available in JSON, Else it should reject the request.
My project is using "$schema":"http://json-schema.org/draft-06/schema#"
Some follow up question?
- How to find which schema draft version using in my project (some schema json file there is no draft version in the top)?
- Which maven dependency is supporting this schema draft version ?
required
keyword takes a list of property names, not a boolean. It should live at the same level as"type": "object"
and"properties"
.https://json-schema.org/understanding-json-schema/reference/object.html#required-properties
anyOf
to check for the availability of any of a multiple number of properties.https://json-schema.org/understanding-json-schema/reference/conditionals.html