Validate JSON - require object based on property of other object

49 views
Skip to first unread message

ANIL R

unread,
May 9, 2018, 4:13:32 AM5/9/18
to JSON Schema

I would like to validate a JSON schema (as shown below). In the schema below what I tried for required is not correct. I need to validate schema in two ways as below:

  1. If Object1_Property1 is exist in Object1, then Object2 is required, else not required.
  2. If the value Object1_Property1 of Object1 is "Result", then Object2 is required, else not required.

Could you please help with this?



{
    "$schema": "http://json-schema.org/draft-04/schema",
    "title": "Company-name",
    "type": "object",
    "additionalProperties": false,
    "properties": {
        "Object1": {
            "additionalProperties": false,
            "properties": {
                "Object1_Property1": {
                    "type": "string"
                },
                "Object1_Property2": {
                    "type": "string"
                }
            },
            "required": ["Object1_Property1", "Object1_Property2"]
        },
        "Object2": {
            "description": "xyz",
            "type": "object",
            "properties": {
                "Object2_Property1": {
                    "type": "string"
                },
                "Object2_Property2": {
                    "type": "string"
                }
            },
            "required": ["Object2_Property1", "Object2_Property2"]
        }
    },
    "required": ["Object1", "Object2"]
}
Reply all
Reply to author
Forward
0 new messages