I am making a JSON Schema using https://www.jsonschemavalidator.net/ and https://jsonschema.dev/ to validate them and both are giving me the same problem and idk what is wrong
Here is the JSON that I am using
{
"Cdtr": {
"Id": {
"PrvtId": {
"Othr": {
"Id": "123456"
"SchmeNm": {
"Cd": "NIDN"
}
}
}
}
}
}
and here is the JSON Schema
{
"allOf": [
{
"if": {
"properties": {
"Cdtr": {
"properties": {
"Id": {
"properties": {
"PrvtId": {
"properties": {
"Othr": {
"properties": {
"SchmeNm": {
"Cd": {
"enum": [
"NIDN",
"CCPT",
"ANRU"
]
}
}
}
}
}
}
}
}
}
}
}
},
"then": {
"properties": {
"Cdtr": {
"properties": {
"Id": {
"properties": {
"PrvtId": {
"properties": {
"Othr": {
"properties": {
"Id": {
"maxLength": 8,
"minLength": 6,
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
},
{
"if": {
"properties": {
"Cdtr": {
"properties": {
"Id": {
"properties": {
"PrvtId": {
"properties": {
"Othr": {
"properties": {
"SchmeNm": {
"Cd": {
"const": "CUST"
}
}
}
}
}
}
}
}
}
}
}
},
"then": {
"properties": {
"Cdtr": {
"properties": {
"Id": {
"properties": {
"PrvtId": {
"properties": {
"Othr": {
"properties": {
"Id": {
"minLength": 6,
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
},
{
"if": {
"properties": {
"Cdtr": {
"properties": {
"Id": {
"properties": {
"PrvtId": {
"properties": {
"Othr": {
"properties": {
"SchmeNm": {
"Cd": {
"const": "TXID"
}
}
}
}
}
}
}
}
}
}
}
},
"then": {
"properties": {
"Cdtr": {
"properties": {
"Id": {
"properties": {
"PrvtId": {
"properties": {
"Othr": {
"properties": {
"Id": {
"oneOf": [
{
"maxLength": 8,
"minLength": 8
},
{
"maxLength": 11,
"minLength": 11
}
],
"type": "string"
}
}
}
}
}
}
}
}
}
}
}
}
],
"$schema": "http://json-schema.org/draft-07/schema#",
"description": "PERU C2C BANK",
"properties": {
"Cdtr": {
"properties": {
"Id": {
"properties": {
"PrvtId": {
"properties": {
"Othr": {
"properties": {
"Id": {
"pattern": "^[0-9]+$",
"type": "string"
},
"SchmeNm": {
"properties": {
"Cd": {
"enum": [
"NIDN",
"CCPT",
"TXID",
"ANRU",
"CUST"
],
"maxLength": 4,
"minLength": 4,
"type": "string"
}
},
"required": [
"Cd"
]
}
},
"required": [
"Id",
"SchmeNm"
]
}
},
"required": [
"Othr"
]
}
},
"required": [
"PrvtId"
]
}
},
"required": [
"Id"
]
}
},
"required": [
"Cdtr"
]
}
This case should be "valid" in case of the first if schema but I get an error for the last validation

If you're interested in cleaning up the readability a bit, you can use
definitionsto define your complex schemas and then use aoneOfto reference each of them.You can read more about different patterns used in JSON Schema authoring here