According to JSON-Schema 7.0 String section, I can use a "relative-json-pointer"
to make sure that a property value is an exact match of a parent key.
In the examples section (5.1) of Relative JSON Pointers, it shows that "going up one level" and get the key value, is "0#"
.
Given the following JSON document:
{
"valid": {
"name": "valid"
},
"invalid": {
"name": "invalid, because this value is not the same value as the parent key"
}
}
The following json-schema should catch the "invalid"
object:
{
"$schema": "http://json-schema.org/draft-07/schema#",
"type": "object",
"additionalProperties": {
"type": "object",
"required": ["name"],
"properties": {
"name": {
"type": "string",
"json-pointer": "0#"
}
}
}
}
I am sure the json-schema is sound, since it will catch the two objects, "invalid2"
and "invalid3"
, in the following JSON document:
{
"valid": {
"name": "valid"
},
"invalid": {
"name": "invalid, because this value is not the same value as the parent key"
},
"invalid2": { },
"invalid3": { "name": 2 }
}
I have used ajv-cli 3.3.0 and python jsonschema 3.2.0 to test with. But neither validation implementations will catch the "invalid"
object. Both implementations claim to fully support JSON Schema draft 7.