|
I am new to JSON and JSON schema validation. I am using Draft-3 schema specification.
I have the following schema to validate a single employee object:
{
"$schema":"http://json-schema.org/draft-03/schema#", "title":"Employee Type Schema", "type":"object", "properties": { "EmployeeID": {"type": "integer","minimum": 101,"maximum": 901,"required":true}, "FirstName": {"type": "string","required":true}, "LastName": {"type": "string","required":true}, "JobTitle": {"type": "string"}, "PhoneNumber": {"type": "string","required":true}, "Email": {"type": "string","required":true}, "Address": { "type": "object", "properties": { "AddressLine": {"type": "string","required":true}, "City": {"type": "string","required":true}, "PostalCode": {"type": "string","required":true}, "StateProvinceName": {"type": "string","required":true} } }, "CountryRegionName": {"type": "string"} } } And I have the following schema to validate an array of the same employee object:
{
"$schema": "http://json-schema.org/draft-03/schema#", "title": "Employee set", "type": "array", "items": { "type": "object", "properties": { "EmployeeID": {"type": "integer","minimum": 101,"maximum": 301,"required":true}, "FirstName": {"type": "string","required":true}, "LastName": {"type": "string","required":true}, "JobTitle": {"type": "string"}, "PhoneNumber": {"type": "string","required":true}, "Email": {"type": "string","required":true}, "Address": { "type": "object", "properties": { "AddressLine": {"type": "string","required":true}, "City": {"type": "string","required":true}, "PostalCode": {"type": "string","required":true}, "StateProvinceName": {"type": "string","required":true} } }, "CountryRegionName": {"type": "string"} } } } Is it possible to create one single schema (I mean file) that would validate both a single employee instance and an rray of the employee object?
Sample data to test schemas:
{
"EmployeeID": 203, "FirstName": "Squidward", "LastName": "Tentacles", "JobTitle": "Cashier", "Email": "Squidward.Tentacles&KrustyKrab.com", "PhoneNumber": "(212)306-5000", "Address": { "AddressLine": "15 Spongebob Parkway", "City": "Bikini Bottom", "PostalCode": "72834", "StateProvinceName": "BB" }, "CountryRegionName": "Down Under" } |