From the course: JSON Essential Training

Unlock this course with a free trial

Join today to access over 25,300 courses taught by industry experts.

Specify required properties with JSON Schema

Specify required properties with JSON Schema - JavaScript Tutorial

From the course: JSON Essential Training

Specify required properties with JSON Schema

- [Instructor] In addition to specifying data types for the properties of JSON data, JSON schema also allows you to specify that one or more properties are required. At this point, my schema specifies a data structure for an array that contains objects and each object contains five properties, ID, name, description, image title and image. What if I want to require that these properties must be included in order for my JSON data to be considered valid? Well, remember that each sub object within the array is itself specified by an object in JSON schema with a type property set to object and a property's property specifying the names of properties it can contain. To indicate that one or more of these properties are required, I simply add another property to the object in my JSON schema. The property must have the name required and its value is an array containing one or more strings as its elements. Each string in the…

Contents