Skip to content

Assert that value must appear once somewhere else in JSON #706

Closed
@caleb531

Description

@caleb531

Hi there,

As far as I know, this would be considered a feature request because I haven't found a way to do in via any features available in the current Draft-07 JSON Schema. The title of this issue sounds slightly strange, but the idea is extremely simple.

Consider the following JSON:

{
  "favorite_animal": 32,
  "animals": [
    {
      "id": 57,
      "name": "Llama"
    },
    {
      "id": 32,
      "name": "Red Panda"
    },
    {
      "id": 95,
      "name": "Otter"
    }
  ]
}

My aim is to have some schema-driven way of asserting that favorite_animal maps to an id of one of the objects in the animals array. Specifically, it must map to exactly one id, but depending on how this is implemented, it could be implemented in the spirit of the oneOf, anyOf, and allOf family of keywords.

Is this already possible via some means of $ref and whatnot, or am I out of luck? If the latter, is this use case seem practical and useful enough to warrant crafting functionality for it in JSON Schema?

Thanks,
Caleb

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Status

    Closed

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions