Unevaluated Items

What are Unevaluated Items?

So far, we have used items, prefixItems and contains keywords to define subschemas for the elements of an array. However, sometimes you many want to handle the items that are unevaluated by these keywords.

In such cases, you can use the unevaluatedItems keyword to define a subschema for the unevaluated items in the array.

  • By definition, the unevaluatedItems subschema is always applied after prefixItems, items, and contains subschemas.
  • As its name implies, unevaluatedItems applies to any array index that has not been previously evaluated.

Example

Consider, we have defined array items with prefixItems. When you have items more than the defined prefixItems, you can use unevaluatedItems to define a subschemas for the remaining items.

1{
2  "type": "array",
3  "prefixItems": [
4    { "type": "number" },
5    { "type": "string" }
6  ],
7  "unevaluatedItems": { "type": "number" }
8}

In this case, first two items are evaluated by prefixItems and the remaining items are evaluated by unevaluatedItems.

Task

1{
2  "name": "John Doe",
3  "age": 30,
4  "skills": ["HTML", "CSS", "JavaScript", "React", "Node.js"]
5}

Modify the skills property of the given schema on the side editor such that,

  • First three elements can have only "HTML", "CSS" and "JavaScript" as values (in any order), not anything else.
  • The remaining elements are of type string.

Hints:

  • For the first constraint use prefixItems combined with enum keyword.
  • For the second constraint use unevaluatedItems keyword.
Loading...
Output
Please click the button or use
Shift+Enter
to view the output