Required Properties
In the previous example, the name had three properties: firstName, lastName, and middleName.
What if you want to make firstName and lastName properties mandatory?
1{ 2 "name": { 3 "firstName": "John", 4 "lastName": "Doe", 5 "middleName": "Smith" 6 } 7 "age": 25, 8}
Schema Definition
In JSON Schema, you can define required properties using the required keyword.
Properties listed in the required array must be present in the object. if those properties are not present, the JSON data is considered invalid.
Example
1{ 2 ... 3 "name": { 4 "type": "object", 5 "properties": {...}, 6 "required": ["property1", "property2"], 7 } 8}
Now, try to modify the name property on the side editor and add firstName and lastName as required properties.
Loading...
Output
Please click the button or use
Shift+Enter
to view the output