Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

JSON Schemas can also be written to conditionally apply annotations. For example, consider the following JSON Schema:

Code Block
languagejson
{
  "type": "object",
  "properties": {
    "country": {
      "type": "string",
      "enum": ["United States", "Canada"]
    },
    "if": {
      "properties": {
        "country": {
          "const": "United States"
        }
      },
      "required": ["country"]
    },
    "then": {
      "properties": {
        "measurementSystem": {
          "const": "Imperial"
        }
      }
    },
    "else": {
      "properties": {
        "measurementSystem": {
          "const": "Metric"
        }
      }
    }
  }
}

...