Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Playground (inline)

The Full-Page Visual Editor adds visual editing, engine settings and resizable panels. This page embeds the same editor inline, with a read-only diagram, for quick checks.

Try JSONLogic expressions in your browser. This playground runs the @goplasmatic/datalogic-ui debugger on the datalogic-rs 5.9.0 engine, compiled to WebAssembly.

How to Use

  1. Logic: Enter your JSONLogic expression in the Logic panel
  2. Data: Enter the JSON data to evaluate against in the Data panel
  3. Result: Read the evaluated output, or the engine’s error with its type and failing operator
  4. Diagram: View the diagram of your logic expression and step through the evaluation with the debugger controls (Space, arrow keys, Home/End once you click the diagram)
  5. Examples: Use the Load Example… dropdown to load pre-built examples
  6. Templating: Tick the checkbox to compile multi-key objects as output templates with embedded JSONLogic

Quick Reference

Basic Operators

OperatorExampleDescription
var{"var": "x"}Access variable
=={"==": [1, 1]}Equality
>, <, >=, <={">": [5, 3]}Comparison
and, or{"and": [true, true]}Logical
if{"if": [cond, then, else]}Conditional
+, -, *, /{"+": [1, 2]}Arithmetic

Array Operations

OperatorExampleDescription
map{"map": [arr, expr]}Transform elements
filter{"filter": [arr, cond]}Filter elements
reduce{"reduce": [arr, expr, init]}Reduce to value
all, some, none{"all": [arr, cond]}Check conditions

String Operations

OperatorExampleDescription
cat{"cat": ["a", "b"]}Concatenate
substr{"substr": ["hello", 0, 2]}Substring
in{"in": ["@", "a@b.com"]}Contains

Example: Feature Flag

Determine if a user has access to a premium feature:

{
  "and": [
    {"==": [{"var": "user.plan"}, "premium"]},
    {">=": [{"var": "user.accountAge"}, 30]}
  ]
}

Data:

{
  "user": {
    "plan": "premium",
    "accountAge": 45
  }
}

Example: Dynamic Pricing

Calculate a discounted price based on quantity:

{
  "if": [
    {">=": [{"var": "quantity"}, 100]},
    {"*": [{"var": "price"}, 0.8]},
    {"if": [
      {">=": [{"var": "quantity"}, 50]},
      {"*": [{"var": "price"}, 0.9]},
      {"var": "price"}
    ]}
  ]
}

Data:

{
  "quantity": 75,
  "price": 100
}

Learn More