Choice in JSON Schema

133 views
Skip to first unread message

N

unread,
Jun 7, 2016, 7:10:46 AM6/7/16
to JSON Schema
Hi,

I am trying to create a json schema. My requirement is that it should accept only "contactId" or ("firstName" and "lastName").

Here is my shcema:

{

  "type": "object",
    "properties": {
      "contactId": {
        "type": "string"
      },
      "firstName": {
        "type": "string"
      },
      "lastName": {
        "type": "string"
      }
    },
    
    "oneOf": [
      {"required": ["contactId"]},
      {"required": ["firstName"]},
      {"required": ["lastName"]}
    ],
    "additionalProperties": false
}

Valid input:
1.
{
      "contactId": "385b1d9f-87fe-4f33-8672-ec365583138e"
}

2. 
{
      "city": "FirstName", 
      "state":"ssds"
}

Invalid Input:

{
      "contactId": "385b1d9f-87fe-4f33-8672-ec365583138e",
      "city": "FirstName", 
        "state":"ssds"
}

Any help?

N

unread,
Jun 7, 2016, 7:13:42 AM6/7/16
to JSON Schema
********Correction***********
Valid input:
1.
{
      "contactId": "385b1d9f-87fe-4f33-8672-ec365583138e"
}

2. 
{
      "firstName": "FirstName", 
      "lastName":"ssds"
}

Invalid Input:

{
      "contactId": "385b1d9f-87fe-4f33-8672-ec365583138e",
      "firstName": "FirstName", 
      "lastName":"ssds"
}

Any help?
Reply all
Reply to author
Forward
0 new messages