Flag Types
Boolean, string, number, and JSON — choose the right flag type for your use case
Flagpool supports four flag types. Each type determines what kind of values the flag can return.
Boolean
The most common flag type. Returns true or false.
Use cases: feature toggles, kill switches, permission gates.
if (client.isEnabled('new-checkout')) {
showNewCheckout()
}
Default variations:
| Index | Name | Value |
|---|---|---|
| 0 | On | true |
| 1 | Off | false |
String
Returns a string value. You can define multiple string variations.
Use cases: A/B tests, theme selection, copy experiments, variant routing.
const color = client.getValue('cta-button-color')
// 'blue' | 'green' | 'orange'
Example variations:
| Index | Name | Value |
|---|---|---|
| 0 | Blue | "blue" |
| 1 | Green | "green" |
| 2 | Orange | "orange" |
Use targeting rules or rollout percentages to control which users get which variation.
Number
Returns a numeric value.
Use cases: rate limits, thresholds, batch sizes, configuration values.
const limit = client.getValue('max-upload-size-mb')
// 10 | 100 | 500 | 1000
Example variations:
| Index | Name | Value |
|---|---|---|
| 0 | Free | 10 |
| 1 | Pro | 100 |
| 2 | Enterprise | 1000 |
Combined with targeting rules (e.g., plan eq "enterprise" → variation 2), this lets you gate numeric limits by subscription tier.
JSON
Returns a structured JSON object. Useful when you need to configure multiple settings with a single flag.
Use cases: complex feature configurations, multi-value experiments, layout configurations.
const config = client.getValue('checkout-config')
// { showCoupons: true, maxItems: 50, paymentMethods: ['card', 'paypal'] }
Example variations:
| Index | Name | Value |
|---|---|---|
| 0 | Default | { "showCoupons": false, "maxItems": 10 } |
| 1 | Enhanced | { "showCoupons": true, "maxItems": 50 } |
JSON flags are powerful but harder to manage. Prefer simpler types when possible and reserve JSON for cases where multiple values must change together.
Choosing the right type
| Scenario | Recommended type |
|---|---|
| Feature on/off | Boolean |
| Kill switch | Boolean |
| A/B test between two designs | String |
| Rate limit per plan | Number |
| Complex feature config | JSON |
| Theme/color selection | String |
| Batch size tuning | Number |
Variations
Every flag has an array of variations — the possible values it can return. The number of variations depends on the flag type:
- Boolean flags always have exactly 2 variations (true/false)
- String, Number, and JSON flags can have 2 or more variations
Targeting rules and rollout logic select which variation to return by referencing the variation index (0, 1, 2, ...).
Reading flag values in code
| Method | Best for | Returns |
|---|---|---|
isEnabled(key) | Boolean flags | boolean |
getValue(key) | Any flag type | The raw variation value |
getVariation(key) | Alias for getValue | The raw variation value |
In React:
| Hook | Best for | Returns |
|---|---|---|
useFlag(key) | Boolean flags | boolean |
useFlagValue(key, default) | Any flag type | The variation value (typed) |
useFlagDetails(key, default) | Any type + loading states | { value, isLoading, error } |
Next steps
- Feature Flags — how evaluation works end to end
- Targeting — route users to specific variations
- A/B Testing Guide — string flags in practice