Question

I get an "Additional properties are not allowed" error on each and every key in the JSON item. Below is the schema and item.

Schema:

    {
      "additionalProperties": false,
      "category": {
        "admin": {"type": "boolean"}
      },
      "username": {"type": "string"},
      "password": {"type": "string"},
      "name": {"type": "string"},
      "email": {"type": "string", "format": "email"},
      "phone": {"type": "string"},
      "hours": {
        "type": "array",
        "items": {
          "start": {"type": "string", "format": "date-time"},
          "end": {"type": "string", "format": "date-time"}
        }
      }
    }

Item:

    {
        "username": "emanb29",
        "password": "$2a$10$THISISAPASSWORDHASH",
        "name": "Ethan Bell",
        "email": "eb@ethanbell.me",
        "phone": "5555555555",
        "hours": [
            {
                "start": "1998-05-29T04:00:00Z",
                "end": "1999-05-29T04:00:00Z"
            },
            {
                "start": "2001-05-29T10:20:00Z",
                "end": "2001-05-29T22:20:00Z"
            }
        ],
        "category": {
            "admin": true
        }
    }
Was it helpful?

Solution

Your schema seems suspect. Working from the samples on jsonschemalint.com I created a properties container in the root for your properties, added description and type at the root and moved additionalProperties to the root as well.

This validates your item on jsonschemalint.com:

{
    "description": "StackOverflow test schema", 
    "type": "object", 
    "additionalProperties": false,
    "properties":     {
      "category": {
        "admin": {"type": "boolean"}
      },
      "username": {"type": "string"},
      "password": {"type": "string"},
      "name": {"type": "string"},
      "email": {"type": "string", "format": "email"},
      "phone": {"type": "string"},
      "hours": {
        "type": "array",
        "items": {
          "start": {"type": "string", "format": "date-time"},
          "end": {"type": "string", "format": "date-time"}
        }
      }
    }
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top