Example Templates

27 pre-built JSONLogic rules across 7 categories

All Examples

Showing 27 examples

AI / LLM

LLM Model Router

Route to different AI models based on task complexity and user tier

JSONLogic:
{
  "if": [
    {
      ">=": [
        {
          "var": "tokens"
        },
        5000
      ]
    },
    "claude-sonnet",
    {
      "if": [
        {
          "==": [
            {
              "var": "user.tier"
            },
            "premium"
          ]
        },
        "claude-sonnet",
        "claude-haiku"
      ]
    }
  ]
}
Input:
{
 "tokens": 3000,
 "user": {
  "tier": "free"
 }
}
Output:
"claude-haiku"
AI / LLM

Dynamic Prompt Selection

Choose prompt variant based on user preferences and context

JSONLogic:
{
  "if": [
    {
      "and": [
        {
          "==": [
            {
              "var": "user.language"
            },
            "es"
          ]
        },
        {
          "==": [
            {
              "var": "task"
            },
            "translate"
          ]
        }
      ]
    },
    "prompt_spanish_translation",
    {
      "if": [
        {
          "==": [
            {
              "var": "user.verbose"
            },
            true
          ]
        },
        "prompt_detailed",
        "prompt_concise"
      ]
    }
  ]
}
Input:
{
 "user": {
  "language": "en",
  "verbose": true
 },
 "task": "summarize"
}
Output:
"prompt_detailed"
AI / LLM

Content Safety Gate

Block certain topics or enable guardrails based on user type

JSONLogic:
{
  "if": [
    {
      "or": [
        {
          "==": [
            {
              "var": "user.age"
            },
            null
          ]
        },
        {
          "<": [
            {
              "var": "user.age"
            },
            18
          ]
        }
      ]
    },
    true,
    false
  ]
}
Input:
{
 "user": {
  "age": 16
 }
}
Output:
true
Validation

Age Verification

Check if user meets minimum age requirement

JSONLogic:
{
  ">=": [
    {
      "var": "age"
    },
    18
  ]
}
Input:
{
 "age": 21
}
Output:
true
Pricing

Premium User Discount

Apply discount if user is premium and order exceeds threshold

JSONLogic:
{
  "if": [
    {
      "and": [
        {
          "==": [
            {
              "var": "user.tier"
            },
            "premium"
          ]
        },
        {
          ">": [
            {
              "var": "order.total"
            },
            100
          ]
        }
      ]
    },
    {
      "*": [
        {
          "var": "order.total"
        },
        0.9
      ]
    },
    {
      "var": "order.total"
    }
  ]
}
Input:
{
 "user": {
  "tier": "premium"
 },
 "order": {
  "total": 150
 }
}
Output:
135
General

Business Hours Check

Verify if current hour is within business hours

JSONLogic:
{
  "and": [
    {
      ">=": [
        {
          "var": "hour"
        },
        9
      ]
    },
    {
      "<": [
        {
          "var": "hour"
        },
        17
      ]
    }
  ]
}
Input:
{
 "hour": 14
}
Output:
true
Validation

Multi-Condition Approval

Approve request if user meets multiple criteria

JSONLogic:
{
  "and": [
    {
      ">=": [
        {
          "var": "user.accountAge"
        },
        30
      ]
    },
    {
      ">=": [
        {
          "var": "user.creditScore"
        },
        650
      ]
    },
    {
      "<=": [
        {
          "var": "requestAmount"
        },
        5000
      ]
    }
  ]
}
Input:
{
 "user": {
  "accountAge": 45,
  "creditScore": 720
 },
 "requestAmount": 3000
}
Output:
true
Arrays

Array Some Check

Check if some items in array meet a condition (e.g., any item qty > 1)

JSONLogic:
{
  "some": [
    {
      "var": "items"
    },
    {
      ">": [
        {
          "var": "qty"
        },
        1
      ]
    }
  ]
}
Input:
{
 "items": [
  {
   "name": "apple",
   "qty": 1
  },
  {
   "name": "banana",
   "qty": 3
  }
 ]
}
Output:
true
Arrays

Array All Check

Verify that all items in array meet a condition

JSONLogic:
{
  "all": [
    {
      "var": "items"
    },
    {
      ">=": [
        {
          "var": "price"
        },
        0
      ]
    }
  ]
}
Input:
{
 "items": [
  {
   "item": "apple",
   "price": 1.5
  },
  {
   "item": "banana",
   "price": 2
  }
 ]
}
Output:
true
Arrays

Filter Expensive Items

Filter array to keep only items above price threshold

JSONLogic:
{
  "filter": [
    {
      "var": "products"
    },
    {
      ">": [
        {
          "var": "price"
        },
        100
      ]
    }
  ]
}
Input:
{
 "products": [
  {
   "name": "Laptop",
   "price": 999
  },
  {
   "name": "Mouse",
   "price": 25
  },
  {
   "name": "Monitor",
   "price": 450
  }
 ]
}
Output:
[
 {
  "name": "Laptop",
  "price": 999
 },
 {
  "name": "Monitor",
  "price": 450
 }
]
Arrays

Extract Names from Array

Map over array to extract specific field from each object

JSONLogic:
{
  "map": [
    {
      "var": "users"
    },
    {
      "var": "name"
    }
  ]
}
Input:
{
 "users": [
  {
   "name": "Alice",
   "age": 30
  },
  {
   "name": "Bob",
   "age": 25
  }
 ]
}
Output:
[
 "Alice",
 "Bob"
]
Arrays

Sum Array Values

Use reduce to calculate total of array values

JSONLogic:
{
  "reduce": [
    {
      "var": "numbers"
    },
    {
      "+": [
        {
          "var": "current"
        },
        {
          "var": "accumulator"
        }
      ]
    },
    0
  ]
}
Input:
{
 "numbers": [
  1,
  2,
  3,
  4,
  5
 ]
}
Output:
15
Arrays

Array None Check

Verify that no items in array meet a condition

JSONLogic:
{
  "none": [
    {
      "var": "items"
    },
    {
      "<": [
        {
          "var": "stock"
        },
        0
      ]
    }
  ]
}
Input:
{
 "items": [
  {
   "name": "apple",
   "stock": 10
  },
  {
   "name": "banana",
   "stock": 5
  }
 ]
}
Output:
true
Arrays

Merge Arrays

Combine multiple arrays into one

JSONLogic:
{
  "merge": [
    {
      "var": "list1"
    },
    {
      "var": "list2"
    }
  ]
}
Input:
{
 "list1": [
  "apple",
  "banana"
 ],
 "list2": [
  "cherry",
  "date"
 ]
}
Output:
[
 "apple",
 "banana",
 "cherry",
 "date"
]
Strings

String Concatenation

Combine multiple strings into one

JSONLogic:
{
  "cat": [
    {
      "var": "firstName"
    },
    " ",
    {
      "var": "lastName"
    }
  ]
}
Input:
{
 "firstName": "John",
 "lastName": "Doe"
}
Output:
"John Doe"
Strings

Extract Substring

Extract portion of string using substr operation

JSONLogic:
{
  "substr": [
    {
      "var": "text"
    },
    0,
    5
  ]
}
Input:
{
 "text": "Hello World"
}
Output:
"Hello"
Strings

String Contains Check

Check if a substring exists in a string

JSONLogic:
{
  "in": [
    "hello",
    {
      "var": "message"
    }
  ]
}
Input:
{
 "message": "hello world"
}
Output:
true
Validation

Missing Fields Validation

Check if required fields are present in data

JSONLogic:
{
  "if": [
    {
      "missing": [
        "firstName",
        "lastName",
        "email"
      ]
    },
    {
      "cat": [
        "Missing required fields: ",
        {
          "missing": [
            "firstName",
            "lastName",
            "email"
          ]
        }
      ]
    },
    "All fields present"
  ]
}
Input:
{
 "firstName": "Jane",
 "email": "[email protected]"
}
Output:
"Missing required fields: lastName"
Validation

Value in Array Check

Check if a value exists in an array

JSONLogic:
{
  "in": [
    {
      "var": "status"
    },
    [
      "active",
      "pending",
      "approved"
    ]
  ]
}
Input:
{
 "status": "pending"
}
Output:
true
Math

Addition

Add multiple numbers together

JSONLogic:
{
  "+": [
    {
      "var": "a"
    },
    {
      "var": "b"
    },
    {
      "var": "c"
    }
  ]
}
Input:
{
 "a": 10,
 "b": 20,
 "c": 5
}
Output:
35
Math

Subtraction

Subtract one number from another

JSONLogic:
{
  "-": [
    {
      "var": "total"
    },
    {
      "var": "discount"
    }
  ]
}
Input:
{
 "total": 100,
 "discount": 15
}
Output:
85
Math

Multiplication

Multiply numbers together

JSONLogic:
{
  "*": [
    {
      "var": "price"
    },
    {
      "var": "quantity"
    }
  ]
}
Input:
{
 "price": 25.5,
 "quantity": 4
}
Output:
102
Math

Division

Divide one number by another

JSONLogic:
{
  "/": [
    {
      "var": "total"
    },
    {
      "var": "count"
    }
  ]
}
Input:
{
 "total": 100,
 "count": 4
}
Output:
25
Math

Modulo (Remainder)

Get remainder of division operation

JSONLogic:
{
  "%": [
    {
      "var": "number"
    },
    2
  ]
}
Input:
{
 "number": 17
}
Output:
1
Math

Min and Max Values

Find minimum and maximum from numbers

JSONLogic:
{
  "max": [
    {
      "var": "scores"
    }
  ]
}
Input:
{
 "scores": [
  85,
  92,
  78,
  95,
  88
 ]
}
Output:
95
General

Nested Conditionals

Complex decision tree with multiple if-then-else branches

JSONLogic:
{
  "if": [
    {
      "<": [
        {
          "var": "age"
        },
        13
      ]
    },
    "child",
    {
      "if": [
        {
          "<": [
            {
              "var": "age"
            },
            20
          ]
        },
        "teenager",
        {
          "if": [
            {
              "<": [
                {
                  "var": "age"
                },
                65
              ]
            },
            "adult",
            "senior"
          ]
        }
      ]
    }
  ]
}
Input:
{
 "age": 45
}
Output:
"adult"
Math

Logarithm

Calculate logarithm of a number

JSONLogic:
{
  "log": [
    {
      "var": "value"
    }
  ]
}
Input:
{
 "value": 100
}
Output:
2

Ready to build your own rules?

Open Visual Editor