Applying Schema to Property Names
In JSON Schema, you can apply schema to property names using the propertyNames keyword. This keyword allows you to define a schema that restricts the property names of an object.
Example
We want to ensure that each property names are written in capital letters. We can use the propertyNames keyword to enforce this rule.
Example:
1{ 2 "type": "object", 3 "propertyNames": { 4 "pattern": "^[A-Z]+$" 5 } 6}
You are given an empty object schema in the side editor. Modify it ensure that it follows the below constraints:
- The object should have at least 2 properties.
- The property names should be written in capital letters, and should have minimum length of 3 characters.
- The property values should be either string or integer.
Hints:
- For the first constraint, you can use the minProperties keyword.
- For the second constraint, you can use the propertyNames keyword with the pattern keyword.
- For the third constraint, you can use the additionalProperties keyword with the type keyword.
Loading...
Output
Please click the button or use
Shift+Enter
to view the output