Understanding the OpenFeature JSON Schema

👉 flag.json

The following JSON is based on OpenFeature Schema. It includes three flag keys:

  1. newTitle: Since the flag doesn't contain variants, so it behaves as a boolean flag. Here the state is enabled so the flag resolves to true.

  2. color: Since returnType is defined as "number", it resolves to a numeric value. There are four variants: "red", "green", "blue" & "orange" that the flag could resolve to. If any rule condition matches for the provided context then the variant in "action" object is resolved. For instance, if the provided email is user@feature.test, then it'll match with the second rule, which resolves to "red" variant. That means, the resulting value for the flag will be 4294901760. And if the provided email doesn't match with any of the rules then a defaultVariant is used, which is "blue".

  3. increment: The flag is similar to color. For instance, if email is user@feature.test then the flag will be resolved to value 3. The value is used as a increment factor in the app.

{
  "newTitle": {
    "state": "enabled"
  },
  "color": {
    "returnType": "number",
    "variants": {
      "red": 4294901760,
      "green": 4278255360,
      "blue": 4278190335,
      "orange": 4294934352
    },
    "defaultVariant": "blue",
    "state": "enabled",
    "rules": [
      {
        "action": {
          "variant": "green"
        },
        "conditions": [
          {
            "context": "email",
            "op": "ends_with",
            "value": "@feature.flag"
          }
        ]
      },
      {
        "action": {
          "variant": "red"
        },
        "conditions": [
          {
            "context": "email",
            "op": "ends_with",
            "value": "@feature.test"
          }
        ]
      },
      {
        "action": {
          "variant": "orange"
        },
        "conditions": [
          {
            "context": "email",
            "op": "ends_with",
            "value": "@example.com"
          }
        ]
      }
    ]
  },
  "increment": {
    "returnType": "number",
    "variants": {
      "single": 1,
      "double": 2,
      "triple": 3
    },
    "defaultVariant": "single",
    "state": "enabled",
    "rules": [
      {
        "action": {
          "variant": "double"
        },
        "conditions": [
          {
            "context": "email",
            "op": "ends_with",
            "value": "@feature.flag"
          }
        ]
      },
      {
        "action": {
          "variant": "triple"
        },
        "conditions": [
          {
            "context": "email",
            "op": "ends_with",
            "value": "@feature.test"
          }
        ]
      }
    ]
  }
}