JSON Schema: validating object values ​​without keys

Not to confuse anyone, I'll start by checking the arrays ...

As for arrays, the JSON schema can check if the elements of the sub) array ((...) sub) structure:

"type": "array",
"items": {
  ...
}

      

When inspecting objects, I know that I can pass certain keys with appropriate value types such as:

"type": "object",
"properties": {
  // key-value pairs, might also define subschemas
}

      

But what if I have an object that I want to use to validate only values (no keys)?

In my example, I customize the buttons: there might be buttons for edit, delete, add, etc. They all have a certain rigid structure for which I have a JSON schema. But I do not want to be limited only ['edit', 'delete', 'add']

, in the future maybe publish

or print

. But I know they will all fit my subcircuit.

Each button:

BUTTON = {
  "routing": "...",
  "params": { ... },
  "className": "...",
  "i18nLabel": "..."
}

      

And I have an object (not an array) of buttons:

{
  "edit": BUTTON,
  "delete": BUTTON,
  ...
}

      

How can I write a JSON schema like this? Is there a way to combine object

with items

(I know there are object properties and array properties).

+3


source to share


1 answer


You can use additionalProperties

for this. If you set the additionalProperties

schema instead of boolean, then any properties that are not explicitly declared using keywords properties

or patternProperties

must match the given schema.

{
  "type": "object",
  "additionalProperties": {
    ... BUTTON SCHEMA ...
  }
}

      



http://json-schema.org/latest/json-schema-validation.html#anchor64

+4


source







All Articles