Philip7899
Philip7899

Reputation: 4677

json schema validation not enforcing type

I have a column that stores json. I am trying to make sure that only an array of objects can be stored in this column as described in the json schema below. The schema is working except for that I am able to save the attribute show as a string when it should be forced to be a boolean. For example, [{"name"=>"primary_phone", "show"=> "some text"}] is saving correctly but it shouldn't. How do I enforce that show must be a boolean?

{
  "type": "array",
  "items": {
    "definitions": {
        "name": { "type": "string" },
        "show": {"type": "boolean"}
    },
    "required": ["name", "show"]
  }
  
}

Upvotes: -1

Views: 529

Answers (1)

Ether
Ether

Reputation: 53986

Your schema under "items" is invalid. Perhaps you meant "properties" instead of "definitions"?

Upvotes: 2

Related Questions