1

Wise crowd,

I already have a working JSON Schema (v0.7) to validate my data. This is an example of valid JSON:

{
  "people": [
    { "id": 1, "name": "bob" },
    ...
  ]
}

Now I need to a bunch of strings in it:

{
  "people": [
    { "id": 1, "name": "bob", "appears_in": "long_string_id_1" },
    { "id": 2, "name": "ann", "appears_in": "long_string_id_1" }
    ...
  ],
  "long_strings": {
    "long_string_id_1": "blah blah blah.....",
    ...
  }
}

What I need is:

  • a value for key appears_in MUST be a key of the long_strings object
  • (optional) a key of the long_strings object MUST be used as value in on of the appears_in key

Property dependencies are nice, but don't seem to address my needs.

Any idea?


And this question is not a duplicate, because I do not know the values in advance.

Manu
  • 13
  • 4
  • Possible duplicate of [JSON Schema Validation based on a property](https://stackoverflow.com/questions/55840926/json-schema-validation-based-on-a-property) – Relequestual May 06 '19 at 13:52

1 Answers1

1

Sorry. You cannot do this in JSON schema. You cannot reference data in your schema.

Relequestual
  • 11,631
  • 6
  • 47
  • 83
  • Too bad, but I guess this is the price to pay to have something simpler than an `XML` schema. Thank you for your work on `JSON` Schema and for this answer. – Manu May 06 '19 at 16:22