0

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?

  1. How to find which schema draft version using in my project (some schema json file there is no draft version in the top)?
  2. Which maven dependency is supporting this schema draft version ?
  • 1
    You should not combine multiple questions into a single post. Ask separate questions. – aled Apr 25 '22 at 22:00

1 Answers1

0
  • the 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

  • you can use anyOf to check for the availability of any of a multiple number of properties.

https://json-schema.org/understanding-json-schema/reference/conditionals.html

Ether
  • 53,118
  • 13
  • 86
  • 159