Issues creating Json schema with enums - json

I am new to JSON and I am trying to create a JSON schema for a JSON object. There are tools online that can easily create JSON schema from a JSON object but my JSON seems to be complicated and needs some tweaking, but I am not sure how
example json
{
"iD": 123456789,
"balance": {
"currency": "Pounds",
"balance": 260.25,
"date": "2022-03-03"
},
"Permissions": {
"granted": [
"canLoginWithPassword",
"canGame",
"canWithdraw"
],
"failedConditions": [
{
"name": "we move",
"description": "Deposit Block",
"details": {
"reason": "Deposit Block"
},
"denied": [
"canDeposit"
]
}
]
}
The problem I am having is not being able to represent the granted section and denied section with enumerations. The granted and denied sections can have one or all of the privileges
Privileges
"canLoginWithPassword",
"canGame",
"canWithdraw",
"canDeposit"

From reading your question, I think the items, uniqueItems and enum keywords are the way to go for your schema:
{
"type": "object",
"$schema": "http://json-schema.org/draft-06/schema#",
"description": "JSON schema generated with JSONBuddy https://www.json-buddy.com",
"properties": {
"Permissions": {
"$ref": "#/definitions/Permissions"
},
"balance": {
"$ref": "#/definitions/balance"
},
"iD": {
"type": "integer"
}
},
"definitions": {
"privileges": {
"type": "array",
"uniqueItems": true,
"items": {
"type": "string",
"enum": [
"canLoginWithPassword",
"canGame",
"canWithdraw",
"canDeposit"
]
}
},
"details": {
"type": "object",
"properties": {
"reason": {
"type": "string"
}
}
},
"Permissions": {
"type": "object",
"properties": {
"failedConditions": {
"type": "array",
"items": {
"type": "object",
"properties": {
"denied": {
"$ref": "#/definitions/privileges"
},
"description": {
"type": "string"
},
"details": {
"$ref": "#/definitions/details"
},
"name": {
"type": "string"
}
}
}
},
"granted": {
"$ref": "#/definitions/privileges"
}
}
},
"balance": {
"type": "object",
"properties": {
"balance": {
"type": "number"
},
"currency": {
"type": "string"
},
"date": {
"type": "string"
}
}
}
}
}

Related

Error while creating models for request validation in aws api gateway

I am trying to build model for the request validation in the aws api gateway that i created.
In the model schema, when i use simple json schema, it works. But when i use my schema as below.
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"uuid": {
"type": "string",
"pattern": "^[0-9a-f]{8}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{4}-[0-9a-f]{12}$",
"minLength": 36,
"maxLength": 36
},
"macAddress": {
"type": "string",
"pattern": "([0-9a-fA-F]{2}[:]){5}([0-9a-fA-F]{2})"
},
"locale": {
"type": "string",
"pattern": "^[a-z]{2}(-[A-Z]{2})?$",
"minLength": 2
},
"status": {
"type": "string",
"enum": ["good", "bad", "canceled"]
},
"timezone": {
"type": "string",
"pattern": "^[A-Z][a-z]+/[A-Z][a-z]+$"
},
"device": {
"type": "object",
"additionalProperties": false,
"properties": {
"mac_address": {
"type": "string",
"$ref": "#/definitions/macAddress"
},
"hardware": {
"type": "string"
}
},
"required": ["mac_address"]
},
"started_at": {
"type": "number",
"minimum": 0,
"maximum": 2147483647999
},
"finished_at": {
"type": "number",
"minimum": 0,
"maximum": 2147483647999
},
"questionType": {
"enum": [
"barcode",
"name",
"text"
]
},
"question": {
"type": "object",
"additionalProperties": false,
"properties": {
"key": {
"string"
},
"type": {
"$ref": "#/definitions/questionType"
}
},
"required": ["key", "type"]
},
"answers": {
"type": "array",
"items": {
"type": "object",
"properties": {
"question": {
"$ref": "#/definitions/question"
},
"status": {
"type": "string",
"$ref": "#/definitions/status"
},
"started_at": {
"type": "number",
"$ref": "#/definitions/started_at"
},
"finished_at": {
"type": "number",
"$ref": "#/definitions/finished_at"
}
},
"allOf": [
{"if": {
"properties": { "question": { "properties": {
"type": { "const": "text" }
} } } },
"then": {
"properties": { "value": {"type": "string"} } }
},
{"if": {
"properties": { "question": { "properties": {
"type": { "const": "name" }
} } } },
"then": {
"properties": { "value": {"type": "string" } } }
},
{"if": {
"properties": { "question": { "properties": {
"type": { "const": "barcode" }
}} } },
"then": {
"properties": { "value": {"type": "string" } } }
}
]
}
}
},
"properties": {
"locale": {
"$ref": "#/definitions/locale"
},
"timezone": {
"$ref": "#/definitions/timezone"
},
"device": {
"$ref": "#/definitions/device"
},
"answers": {
"$ref": "#/definitions/answers"
}
},
"required": ["locale"]
}
I get the below error.
validation error detected: Value 'Invalid model specified: Validation Result: warnings : [], errors : [Invalid model schema specified. Unsupported keyword(s): ["if","then"], Invalid model schema specified.
When i read the aws documentation, i see that the json schema draft 4 is supported and i have also used the draft 4 rules to build my schema.
Is there a hack to use the if/then in aws model schema or how can i build the schema without if then?

Assistance needed to create JSON schema

As I am new to JSON schema creation, I have learnt the basics of JSON schema and now I am trying to create JSON schema for the below mentioned set of data,
{
"Result": [
{
"ResourceName": "Appointment",
"Sequence": "1",
"Data": {
"AppointmentID": "A1234",
"PatientName": "Test Patient",
"ClinicName": "Test Clinic"
}
},
{
"ResourceName": "EpisodeofCare",
"Sequence": "2",
"Data": {
"EpisodeID": "EP1234",
"LocationId": "L1234",
"AppointmentId": "A1234",
"TransactionStatus": "2",
"OPNumber": "OP523367"
}
},
{
"ResourceName": "Encounter",
"Sequence": "3",
"Data": {
"EncounterID": "E1234",
"PatientID": "P1234"
}
}
]
}
Can anybody please help me to create JSON schema for this kind of data set.
Thanks in advance for helping me out on this.
Below is the JSON schema i have drafted
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"ResultType": {
"type": "object",
"properties": {
"ResourceName": {
"type": "string"
},
"Sequence": {
"type": "string"
},
"Data": {
"type": "object",
"anyOf": [
{
"$ref": "#/definitions/Appointment"
},
{
"$ref": "#/definitions/EpisodeofCare"
},
{
"$ref": "#/definitions/Encounter"
}
]
}
}
},
"Appointment": {
"type": "object",
"properties": {
"AppointmentID": {
"type": "boolean"
},
"PatientName": {
"type": "string"
},
"ClinicName": {
"type": "string"
}
}
},
"EpisodeofCare": {
"type": "object",
"properties": {
"EpisodeID": {
"type": "string"
},
"LocationId": {
"type": "string"
},
"AppointmentId": {
"type": "string"
},
"TransactionStatus": {
"type": "string"
},
"OPNumber": {
"type": "string"
}
}
},
"Encounter": {
"type": "object",
"properties": {
"EncounterID": {
"type": "string"
},
"PatientID": {
"type": "string"
}
}
}
},
"type": "object",
"properties": {
"Result": {
"type": "array",
"$ref": "#/definitions/ResultType"
}
}
}
Throw it in a schema validator like this one.
You will see errors in your schemas definition and in validation.
First of all check that your schema is valid json (the validator might help):
[
{
{"$ref": "#/definitions/Appointment"} <- unnecessary and invalid braces
},
{
{"$ref": "#/definitions/EpisodeofCare"} <- unnecessary and invalid braces
},
{
{"$ref": "#/definitions/Encounter"} <- unnecessary and invalid braces
}
]
Within the Result property you want each item of the array. You should use the item property instead of ref. As taken from the specification:
The value of "items" MUST be either a valid JSON Schema or an array of valid JSON Schemas.
[...]
If "items" is a schema, validation succeeds if all elements in the array successfully validate against that schema.
Thus you should use
{
"type": "object",
"properties": {
"Result": {
"type": "array",
"items": {
"$ref": "#/definitions/ResultType"
}
}
}
}
Since the schema should be as specific as possible you should constraint the content of the ResourceName properties to the actual data layout.
Use the const property to define a constant value for the ResourceName for each type of Resource. Take for example the Appointment type, which would change to:
"Appointment": {
"type": "object",
"properties": {
"ResourceName": {
"const": "Appointment"
},
"Data": {
"type": "object",
"properties": {
"AppointmentID": {
"type": "string"
},
"PatientName": {
"type": "string"
},
"ClinicName": {
"type": "string"
}
}
}
}
I also changed the type of AppointmentID to string.
Then your ResultType needs to be adjusted. Before you used anyOf to validate the data, now you need it to validate the complete object while still maintaining the overall structure:
"ResultType": {
"allOf": [
{
"type": "object",
"properties": {
"ResourceName": {
"type": "string"
},
"Sequence": {
"type": "string"
},
"Data": true
}
},
{
"anyOf": [
{
"$ref": "#/definitions/Appointment"
},
{
"$ref": "#/definitions/EpisodeofCare"
},
{
"$ref": "#/definitions/Encounter"
}
]
}
]
}
The allOf propertiy implies a and condition. The overall structure (the object) does not care what value ResourceName has or how Data is structured. The specific implementations (the anyOf part) take care of that.
Some final improvements. Use the required property to define the names of properties that must exist in your JSON file. Also add "additionalProperties": false to ensure that only the specified properties are used. And finally constraint your sequence values to be string representations of positive intergers by adding "pattern": "[1-9]\\d*".
Final result:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"definitions": {
"ResultType": {
"allOf": [
{
"type": "object",
"required": [
"ResourceName",
"Sequence",
"Data"
],
"additionalProperties": false,
"properties": {
"ResourceName": {
"type": "string"
},
"Sequence": {
"type": "string",
"pattern": "[1-9]\\d*"
},
"Data": true
}
},
{
"anyOf": [
{
"$ref": "#/definitions/Appointment"
},
{
"$ref": "#/definitions/EpisodeofCare"
},
{
"$ref": "#/definitions/Encounter"
}
]
}
]
},
"Appointment": {
"type": "object",
"properties": {
"ResourceName": {
"const": "Appointment"
},
"Data": {
"type": "object",
"required": [
"AppointmentID",
"PatientName",
"ClinicName"
],
"additionalProperties": false,
"properties": {
"AppointmentID": {
"type": "string"
},
"PatientName": {
"type": "string"
},
"ClinicName": {
"type": "string"
}
}
}
}
},
"EpisodeofCare": {
"type": "object",
"properties": {
"ResourceName": {
"const": "EpisodeofCare"
},
"Data": {
"type": "object",
"required": [
"EpisodeID",
"LocationId",
"AppointmentId",
"TransactionStatus",
"OPNumber"
],
"additionalProperties": false,
"properties": {
"EpisodeID": {
"type": "string"
},
"LocationId": {
"type": "string"
},
"AppointmentId": {
"type": "string"
},
"TransactionStatus": {
"type": "string"
},
"OPNumber": {
"type": "string"
}
}
}
}
},
"Encounter": {
"type": "object",
"properties": {
"ResourceName": {
"const": "Encounter"
},
"Data": {
"type": "object",
"required": [
"EncounterID",
"PatientID"
],
"additionalProperties": false,
"properties": {
"EncounterID": {
"type": "string"
},
"PatientID": {
"type": "string"
}
}
}
}
}
},
"type": "object",
"required": [
"Result"
],
"additionalProperties": false,
"properties": {
"Result": {
"type": "array",
"items": {
"$ref": "#/definitions/ResultType"
}
}
}
}
you can create json schema by online tools which generates json schema from the json
like: https://www.liquid-technologies.com/online-json-to-schema-converter , it also checks if json is valid or not.
Json Schema that you need:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"Result": {
"type": "array",
"items": [
{
"type": "object",
"properties": {
"ResourceName": {
"type": "string"
},
"Sequence": {
"type": "string"
},
"Data": {
"type": "object",
"properties": {
"AppointmentID": {
"type": "string"
},
"PatientName": {
"type": "string"
},
"ClinicName": {
"type": "string"
}
},
"required": [
"AppointmentID",
"PatientName",
"ClinicName"
]
}
},
"required": [
"ResourceName",
"Sequence",
"Data"
]
},
{
"type": "object",
"properties": {
"ResourceName": {
"type": "string"
},
"Sequence": {
"type": "string"
},
"Data": {
"type": "object",
"properties": {
"EpisodeID": {
"type": "string"
},
"LocationId": {
"type": "string"
},
"AppointmentId": {
"type": "string"
},
"TransactionStatus": {
"type": "string"
},
"OPNumber": {
"type": "string"
}
},
"required": [
"EpisodeID",
"LocationId",
"AppointmentId",
"TransactionStatus",
"OPNumber"
]
}
},
"required": [
"ResourceName",
"Sequence",
"Data"
]
},
{
"type": "object",
"properties": {
"ResourceName": {
"type": "string"
},
"Sequence": {
"type": "string"
},
"Data": {
"type": "object",
"properties": {
"EncounterID": {
"type": "string"
},
"PatientID": {
"type": "string"
}
},
"required": [
"EncounterID",
"PatientID"
]
}
},
"required": [
"ResourceName",
"Sequence",
"Data"
]
}
]
}
},
"required": [
"Result"
]
}

Error in Parse JSON step in Microsoft Flow

Sorry for the long question, but I wanted to include all the JSON to get the best help.
we are getting an error parsing JSON from an HTTP Get request in our flow.
Here is the schema we are using in our Parse JSON step:
{
"type": "object",
"properties": {
"d": {
"type": "object",
"properties": {
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"__metadata": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"uri": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"Alerts": {
"type": "object",
"properties": {
"__deferred": {
"type": "object",
"properties": {
"uri": {
"type": "string"
}
}
}
}
},
"Groups": {
"type": "object",
"properties": {
"__deferred": {
"type": "object",
"properties": {
"uri": {
"type": "string"
}
}
}
}
},
"Id": {
"type": "integer"
},
"IsHiddenInUI": {
"type": "boolean"
},
"LoginName": {
"type": "string"
},
"Title": {
"type": "string"
},
"PrincipalType": {
"type": "integer"
},
"Email": {
"type": "string"
},
"IsEmailAuthenticationGuestUser": {
"type": "boolean"
},
"IsShareByEmailGuestUser": {
"type": "boolean"
},
"IsSiteAdmin": {
"type": "boolean"
},
"UserId": {
"type": "object",
"properties": {
"__metadata": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"NameId": {
"type": "string"
},
"NameIdIssuer": {
"type": "string"
}
}
}
},
"required": [
"__metadata",
"Alerts",
"Groups",
"Id",
"IsHiddenInUI",
"LoginName",
"Title",
"PrincipalType",
"Email",
"IsEmailAuthenticationGuestUser",
"IsShareByEmailGuestUser",
"IsSiteAdmin",
"UserId"
]
}
}
}
}
}
}
we are only interested in the Email property that we want to use to send approvals...
here are the INPUTS results of the Parse JSON step that fails:
{
"d": {
"results": [
{
"__metadata": {
"id": "https://*********.sharepoint.com/_api/Web/GetUserById(1691)",
"uri": "https://*********.sharepoint.com/_api/Web/GetUserById(1691)",
"type": "SP.User"
},
"Alerts": {
"__deferred": {
"uri": "https://*********.sharepoint.com/_api/Web/GetUserById(1691)/Alerts"
}
},
"Groups": {
"__deferred": {
"uri": "https://*********.sharepoint.com/_api/Web/GetUserById(1691)/Groups"
}
},
"Id": 1691,
"IsHiddenInUI": false,
"LoginName": "i:0#.f|membership|Surnamei#Company.org.uk",
"Title": "Firstname Surname",
"PrincipalType": 1,
"Email": "Surnamef#Company.org.uk",
"Expiration": "",
"IsEmailAuthenticationGuestUser": false,
"IsShareByEmailGuestUser": false,
"IsSiteAdmin": false,
"UserId": {
"__metadata": {
"type": "SP.UserIdInfo"
},
"NameId": "10033fff9fe67a30",
"NameIdIssuer": "urn:federation:microsoftonline"
},
"UserPrincipalName": "Surnamef#Company.org.uk"
},
}
]
}
here is the schema from the run results of the Parse JSON that fails:
{
"type": "object",
"properties": {
"d": {
"type": "object",
"properties": {
"results": {
"type": "array",
"items": {
"type": "object",
"properties": {
"__metadata": {
"type": "object",
"properties": {
"id": {
"type": "string"
},
"uri": {
"type": "string"
},
"type": {
"type": "string"
}
}
},
"Alerts": {
"type": "object",
"properties": {
"__deferred": {
"type": "object",
"properties": {
"uri": {
"type": "string"
}
}
}
}
},
"Groups": {
"type": "object",
"properties": {
"__deferred": {
"type": "object",
"properties": {
"uri": {
"type": "string"
}
}
}
}
},
"Id": {
"type": "integer"
},
"IsHiddenInUI": {
"type": "boolean"
},
"LoginName": {
"type": "string"
},
"Title": {
"type": "string"
},
"PrincipalType": {
"type": "integer"
},
"Email": {
"type": "string"
},
"IsEmailAuthenticationGuestUser": {
"type": "boolean"
},
"IsShareByEmailGuestUser": {
"type": "boolean"
},
"IsSiteAdmin": {
"type": "boolean"
},
"UserId": {
"type": "object",
"properties": {
"__metadata": {
"type": "object",
"properties": {
"type": {
"type": "string"
}
}
},
"NameId": {
"type": "string"
},
"NameIdIssuer": {
"type": "string"
}
}
}
},
"required": [
"__metadata",
"Alerts",
"Groups",
"Id",
"IsHiddenInUI",
"LoginName",
"Title",
"PrincipalType",
"Email",
"IsEmailAuthenticationGuestUser",
"IsShareByEmailGuestUser",
"IsSiteAdmin",
"UserId"
]
}
}
}
}
}
}
and here is the error in the step from the run history:
[
{
"message": "Invalid type. Expected Object but got Null.",
"lineNumber": 0,
"linePosition": 0,
"path": "d.results[3].UserId",
"schemaId": "#/properties/d/properties/results/items/properties/UserId",
"errorType": "type",
"childErrors": []
}
]
so how can I change the schema to successfully retrieve the email
The problem was caused by UserId being null in several elements of the data received from the HTTP Get, while that is set as required in the JSON Schema...
initially we solved it by using the below in the HTTP Get:
_api/web/sitegroups/getbyname('Legal Owners')/users?$filter=UserId+ne+null
Then we were given a better and more elegant solution on the Power Platform Community:
in the Apply to each step use:
body('Send_an_HTTP_request_to_SharePoint')?['d']?['results']
and within the loop use:
item()?['Email']

Json schema auto completion property

I have already created my own schema on intellij environment, and it's working good, but still have problems in auto completion which provides intellij to the schema,
for example if object "car" defined in json schema then intellij can recognize that there's such object in the schema and intellij will give it as suggestion through out coding json, the problem that I'm facing is that the suggestions are contains all the objects that defined in the schema, but the expectations are to get the objects which defined under the scoop of another object
This is some code of my own schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Pipe File",
"type": "object",
"definitions": {
"Pipe": {
"type": "object",
"properties": {
"components": {
"$ref": "#/definitions/components"
}
},
"required": [
"components"
]
},
"components": {
"description": "section which defines the pipes in the file",
"type": "array",
"minItems": 1,
"items": {
"oneOf": [
{
"$ref": "#/definitions/setValuesComponent"
},
{
"$ref": "#/definitions/invokeWebServicesComp"
}
]
}
},
"setValuesComponent": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"type": {
"enum": [
"setValuesComp"
]
},
"out": {
"type": "object",
"properties": {
"dateFormat": {
"$ref": "#/definitions/setValuesCompOut"
},
"dateTimeFormat": {
"$ref": "#/definitions/setValuesCompOut"
},
"dateFormatBank": {
"$ref": "#/definitions/setValuesCompOut"
}
}
},
"condition": {
}
},
"required": [
"name",
"type",
"out"
]
},
"setValuesCompOut": {
"type": "object",
"properties": {
"exprValue": {
"type": "string"
},
"ctxEntry": {
"type": "string"
},
"value": {
"type": "string"
},
"exprConst": {
"type": "string",
"pattern": "(Class|class)\\.\\w+\\.\\w+"
}
},
"anyOf": [
{
"required": [
"exprValue"
]
},
{
"required": [
"ctxEntry"
]
},
{
"required": [
"value"
]
},
{
"required": [
"exprConst"
]
}
]
},
"invokeWebServicesComp": {
"type": "object",
"properties": {
"name": {
"type": "string"
},
"type": {
"enum": [
"invokeWebServices"
]
},
"mode": {
"enum": [
"innerJoin",
"leftJoin",
"union",
"parallelJoin"
]
},
"method": {
"type": "string"
},
"headers": {
"$ref": "#/definitions/invokeWebServicesCompHeaders"
},
"dataFilePath": {
"type": "string"
},
"restRelativeUrl": {
"type": "string"
},
"in": {
"$ref": "#/definitions/invokeWebServicesCompIn"
},
"out": {
"$ref": "#/definitions/invokeWebServicesCompOut"
}
},
"required": [
"type",
"name",
"out",
"in"
]
},
"invokeWebServicesCompOut": {
"type": "object",
"patternProperties": {
"doc": {
"type": "string",
"pattern": ".+"
}
}
},
"invokeWebServicesCompHeaders": {
"type": "object",
"patternProperties": {
".{1,}": {
"type": "string",
"pattern": ".+"
}
}
},
"invokeWebServicesCompIn": {
"type": "object",
"patternProperties": {
".{1,}": {
"type": "string",
"pattern": ".+"
}
}
},
"properties": {
"pipes": {
"description": "section which defines the mandatory pipes object in the file",
"type": "object",
"patternProperties": {
".{1,}": {
"$ref": "#/definitions/Pipe"
}
}
}
},
"required": [
"pipes"
]
}
}
So what I expected is, when the type of object determined to "setValuesComp", the auto completion will suggest the relevant properties, that's mean it will not suggest "in" property which is belong to "invokeWebServicesComp" not "setValuesComponent".this picture show the auto complete problem in my real environment
Your JSON schema seems to be invalid. The below JSON content should be present inside object type.
"properties": {
"pipes": {
"description": "section which defines the mandatory pipes object in the file",
"type": "object",
"patternProperties": {
".{1,}": {
"$ref": "#/definitions/Pipe"
}
}
}
},
"required": [
"pipes"
]
In your schema, it is present as part of the "definitions". Please make this correction and then check if you are able to get the suggestions.

How to use JSON schema validation against JSON document having arrays?

I have json document which contains three main elements along with sub elements. These elements also have arrays. I validated this document with json schema but I am not sure if there is any simple way to get rid of repeating schema for arrays as the current schema is too long.
JSON Schema:
{
"$schema": "http://json-schema.org/draft-04/schema#",
"id": "/",
"type": "object",
"properties": {
"book": {
"id": "book",
"type": "array",
"items": [
{
"id": "0",
"type": "object",
"properties": {
"isbn": {
"id": "isbn",
"type": "string"
},
"title": {
"id": "title",
"type": "string"
},
"price": {
"id": "price",
"type": "string"
},
"categories": {
"id": "categories",
"type": "array",
"items": [
{
"id": "0",
"type": "object",
"properties": {
"category": {
"id": "category",
"type": "string"
}
}
},
{
"id": "1",
"type": "object",
"properties": {
"category": {
"id": "category",
"type": "string"
}
}
},
{
"id": "2",
"type": "object",
"properties": {
"category": {
"id": "category",
"type": "string"
}
}
}
]
},
"warehouse": {
"id": "warehouse",
"type": "object",
"properties": {
"location": {
"id": "location",
"type": "string"
},
"aisle": {
"id": "aisle",
"type": "string"
},
"shelf": {
"id": "shelf",
"type": "string"
}
}
}
},
"required": [
"isbn",
"title",
"price",
"categories",
"category",
"warehouse"
]
},
{
"id": "1",
"type": "object",
"properties": {
"isbn": {
"id": "isbn",
"type": "string"
},
"title": {
"id": "title",
"type": "string"
},
"price": {
"id": "price",
"type": "string"
},
"categories": {
"id": "categories",
"type": "array",
"items": [
{
"id": "0",
"type": "object",
"properties": {
"category": {
"id": "category",
"type": "string"
}
}
},
{
"id": "1",
"type": "object",
"properties": {
"category": {
"id": "category",
"type": "string"
}
}
},
{
"id": "2",
"type": "object",
"properties": {
"category": {
"id": "category",
"type": "string"
}
}
}
]
},
"warehouse": {
"id": "warehouse",
"type": "object",
"properties": {
"location": {
"id": "location",
"type": "string"
},
"aisle": {
"id": "aisle",
"type": "string"
},
"shelf": {
"id": "shelf",
"type": "string"
}
}
}
}
},
{
"id": "2",
"type": "object",
"properties": {
"isbn": {
"id": "isbn",
"type": "string"
},
"title": {
"id": "title",
"type": "string"
},
"price": {
"id": "price",
"type": "string"
},
"categories": {
"id": "categories",
"type": "array",
"items": [
{
"id": "0",
"type": "object",
"properties": {
"category": {
"id": "category",
"type": "string"
}
}
},
{
"id": "1",
"type": "object",
"properties": {
"category": {
"id": "category",
"type": "string"
}
}
},
{
"id": "2",
"type": "object",
"properties": {
"category": {
"id": "category",
"type": "string"
}
}
}
]
},
"warehouse": {
"id": "warehouse",
"type": "object",
"properties": {
"location": {
"id": "location",
"type": "string"
},
"aisle": {
"id": "aisle",
"type": "string"
},
"shelf": {
"id": "shelf",
"type": "string"
}
}
}
}
}
],
"required": [
"0",
"1",
"2"
]
}
},
"required": [
"book"
]
}
And JSON document:
{
"book":[
{
"isbn":"0-672-33751-7",
"title":"Unity Game Development",
"price":"$55.99",
"categories":[
{
"category":"Game Development"
},
{
"category":"Unit Game Engine"
},
{
"category":"Beginner to Intermediate"
}
],
"warehouse":{
"location":"North Warehouse",
"aisle":"A16",
"shelf":"3"
}
},
{
"isbn":"978-0-9871530-7-4",
"title":"Jquery: Novice to Ninja",
"price":"$39.95",
"categories":[
{
"category":"JavaScript"
},
{
"category":"jQuery"
},
{
"category":"Web Development"
}
],
"warehouse":{
"location":"North Warehouse",
"aisle":"W03",
"shelf":"6"
}
},
{
"isbn":"0-538-74477-4",
"title":"Programming Logic and Design",
"price":"$89.99",
"categories":[
{
"category":"Programming"
},
{
"category":"JavaScript"
},
{
"category":"Computer Logic"
}
],
"warehouse":{
"location":"South Warehouse",
"aisle":"B44",
"shelf":"1"
}
}
]
}
You've got a lot of issues with this schema. I suggest you read http://spacetelescope.github.io/understanding-json-schema/ to get a better understanding of JSON Schema. Below is the corrected schema. I'll give some brief advice, but not a lot of explanation. Go read that link for more info.
id is required to be a absolute URL. "/" is not valid
Don't use id anywhere other than the root of the document. It has some unexpected properties. It's best to just avoid it.
The items keyword should be a schema not an array of schemas. The form you are using is not intended for arrays with a single type of item.
The required keyword applies only to properties in the schema it appears in. Sub-schemas need to define their own required properties.
The required keyword does not work on arrays. Use minItems and maxItems instead.
{
"$schema": "http://json-schema.org/draft-04/schema#",
"type": "object",
"properties": {
"book": {
"type": "array",
"items": {
"type": "object",
"properties": {
"isbn": { "type": "string" },
"title": { "type": "string" },
"price": { "type": "string" },
"categories": {
"type": "array",
"items": {
"type": "object",
"properties": {
"category": { "type": "string" }
},
"required": ["category"]
}
},
"warehouse": {
"type": "object",
"properties": {
"location": { "type": "string" },
"aisle": { "type": "string" },
"shelf": { "type": "string" }
}
}
},
"required": [
"isbn", "title", "price", "categories", "warehouse"
]
}
}
},
"required": ["book"]
}