0

I have following schema:

{
  "$schema": "http://json-schema.org/draft-07/schema#",
  "description": "Bulk Create Entity",
  "title": "Bulk Create Entity",
  "type": "object",
  "properties": {
    "idempotence_key": {
      "description": "Idempotence Key",
      "type": "string"
    },
    "requested_by": {
      "description": "Requested By",
      "type": "string"
    },
    "updated_by_process_id": {
      "description": "Process id which is creating this entity.",
      "type": "string"
    },
    "entity_creation_requests": {
      "description": "Entity creation requests.",
      "type": "array",
      "minItems": 1,
      "items": {
        "title": "Entity Creation Request",
        "type": "object",
        "properties": {
          "type": {
            "description": "Entity Type",
            "type": "string"
          },
          "taxonomies": {
            "description": "Entity Taxonomies",
            "type": "array",
            "items": {
              "title": "Taxonomy",
              "type": "object",
              "properties": {
                "name": {
                  "description": "Taxonomy Name",
                  "type": "string"
                },
                "value": {
                  "description": "Taxonomy Value",
                  "type": "string"
                }
              }
            }
          }
        }
      }
    }
  },
  "required": [
    "idempotence_key",
    "requested_by",
    "updated_by_process_id",
    "entity_creation_requests"
  ]
}

Here, the root level payload is an object which has a key "entity_creation_requests" which is an array of objects which in turn have an array property "taxonomies" which contains a list of key-value pairs.

Now depending on the "type" of the request under "entity_creation_requests", I want to validate the presence of certain keys in the taxonomies list. For example, for the creation request of type "product", I want keys "MRP", "seller" etc. to be present in the taxonomies list.

Can we achieve this using JSON schema validator? {Here is something I have created: https://codebeautify.org/jsonviewer/cb80c728}

Are there any other alternatives?

I am using this in an spring boot application (Java).

  • Does this include helpful hints? https://stackoverflow.com/a/38781027/5127499 – Carsten Jun 02 '20 at 13:15
  • In the examples above, we are working on the root level properties only but in my case, I want the dependency on nested objects and that too on values. I have created this schema but seems not to be working: https://codebeautify.org/jsonviewer/cb80c728 – Tej Pal Sharma Jun 02 '20 at 13:59

0 Answers0