Nesting Objects
You have learned to define an object schema with properties using the properties keyword, and added properties with string and integer types .
In this lesson, you will learn how to nest objects within objects. Let's divide the name property into the three separate components: firstName, lastName, and middleName
1{ 2 "name": { 3 "firstName": "John", 4 "lastName": "Doe", 5 "middleName": "Smith" 6 } 7 "age": 25, 8}
Defining a Subchema
In JSON Schema, A subschema refers to a schema that is nested within another schema.
To nest objects within objects, you can define a property as an object with its own properties. We can call this nested object a subschema.
Example of Name subschema:
1{ 2 ... 3 "name": { 4 "type": "object", 5 "properties": {...}, 6 } 7}
Now, try to modify the name property on the side editor to add firstName, lastName, and middleName with type string.
Loading...
Output
Please click the button or use
Shift+Enter
to view the output