0

I need to validate the following: Json data: { tag: 'picture', picture: 'some string '}

Json schema: { tag: {'type': 'string'}, ??????? // The second key should be the data value of the 'tag'

Edit: I wish to accomplish this with ajv schema validator

Thank you!!

Kshateesh
  • 571
  • 1
  • 8
  • 21

1 Answers1

0

You can use $data reference (requires $data option):

{
  "type": "object",
  "properties": {
    "tag": {"type": "string"}
  },
  "additionalProperties": {}, // any schema for the second property value
  "propertyNames": {
    "anyOf": [
      {"const": "tag"},
      {"const": {"$data": "1/tag"} }
    ]
  }
}

$data is a proposal for the next versions of JSON schema.

See https://runkit.com/esp/59e0d803bf8366001374c2a2

esp
  • 7,314
  • 6
  • 49
  • 79