Json schema limit number of the same object

Viewed 1588

Is there a way, to create a json schema, that limits the number a object can occur? Or make sure, that a object is unique?

In the end, i want something like

 {
  "days": {
   "monday": {
    "schedule": {
     "start_time": "23:35"
    }
   },
   "tuesday": {
    "schedule": {
     "start_time": "23:23"
    }
   }
  }
 }

In this json, each day should only occur once. Like one start time per day.

So far, i tried it with the following schema but not successful at all. With this schema, i can have multiple "monday" objects in my json and the schema is still valid. But what i'm looking for, is a schema that is not valid for more than one object.

 {
   "$schema": "http://json-schema.org/schema#",
   "title": "DayScheduler",
   "type": "object",
   "required": [
     "days"
   ],
   "properties": {
     "days": {
       "monday": {
         "$ref": "#/definitions/scheduler"
       },
       "tuesday": {
         "$ref": "#/definitions/scheduler"
       },
       "wednesday": {
         "$ref": "#/definitions/scheduler"
       },
       "thursday": {
         "$ref": "#/definitions/scheduler"
       },
       "friday": {
         "$ref": "#/definitions/scheduler"
       },
       "saturday": {
         "$ref": "#/definitions/scheduler"
       },
       "sunday": {
         "$ref": "#/definitions/scheduler"
       }
     }
   },
   "definitions": {
     "scheduler": {
       "type": "object",
       "required": [
         "schedule"
       ],
       "properties": {
         "schedule": {
           "type": "object",
           "required": [
             "start_time"
           ],
           "properties": {
             "start_time": {
               "type": "string",
               "pattern": "^([01]?[0-9]|2[0-3]):[0-5][0-9]"
             }
           }
         }
       }
     }
   }
 }

Is there a way to achieve this with a json-schema?

2 Answers
Related