skip to Main Content

The below JSON object will be responsible for rendering a select menu.

Using JSON Schema, is there anyway i can dynamically validate that the value of the default key (in this case "sm") matches at least one of the properties inside the options object?

I have looked at the docs and am hoping that this is possible using a combination of pattern refs and json pointers but cannot find an example of this use case.

{
"top": {
            "label": "Small",
            "default": "sm",
            "options": {
                "none": {
                    "label": "None"
                },
                "sm": {
                    "label": "Small"
                },
                "md": {
                    "label": "Medium"
                },
                "lg": {
                    "label": "Large"
                },
                "xl": {
                    "label": "XL"
                }
            }
        }
}

2

Answers


  1. From what I can see, what you’re asking is not possible.

    • the pattern validation requires a regex pattern
    • the enum validation unfortunately requires an array of values

    One possibility – if you really, really, need this – is to define a vendor extension (but then you’ll need to implement it in your schema validator).

    Login or Signup to reply.
  2. The default keyword is an annotation keyword and is not used for any type of validation purposes. JSON Schema doesn’t support validation of keywords within a schema.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search