javascriptjsonjsonschemajson-schema-validator

JSON schema reference child key


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"
                }
            }
        }
}

Solution

  • From what I can see, what you're asking is not possible.

    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).