Skip to content

if - then - else in json schema #718

Answered by gregsdennis
KelvinVenancio asked this question in Q&A
Discussion options

You must be logged in to vote

The problem you're having is that schemas can only look at what's inside them. They can't look up the schema structure.

That means that the if-then that you have inside your neighborhoods subschema can't see that there's a country property.

You need to move the if-then structures up in the hierarchy so they can see both properties.

{
  "$schema": "http://json-schema.org/draft-07/schema",
  "type": "object",
  "properties": {
    "app": {
      "type": "object",
      "properties": {
        "country": {
          "type": "string",
          "enum": [
            "United States of America",
            "Brazil"
          ]
        },
        "neighborhoods": {
          "type": "object",
 …

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@KelvinVenancio
Comment options

Answer selected by KelvinVenancio
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants