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

Datalogic

The JSONLogic rules engine powering Reframe transformations.

What is Datalogic?

Datalogic is a high-performance Rust implementation of JSONLogic - a standard for expressing business logic as JSON.

In Reframe, Datalogic evaluates all field mappings and business rules during transformation.

Role in Reframe

Transformation Pipeline
        │
        ▼
┌───────────────────┐
│  Field Mapping    │
│  {                │
│    "path": "...", │
│    "logic": {...} │◄──── Datalogic evaluates this
│  }                │
└───────────────────┘
        │
        ▼
   Transformed Data

Key Features

59 Built-in Operators

CategoryExamples
Comparison==, !=, >, <, >=, <=
Booleanand, or, !, !!
Arithmetic+, -, *, /, %, min, max
Stringcat, substr, in, upper, lower
Arraymap, filter, reduce, all, some
Controlif, ?:, ??
Date/Timenow, format_date, parse_date

Pre-Compilation

Rules are compiled once at startup:

  • No parsing during request processing
  • O(1) rule lookup
  • Zero-copy execution

Thread-Safe

  • Safe concurrent evaluation
  • Arc-wrapped compiled rules
  • Native async/Tokio support

Example Rules

Direct Mapping

{"var": "data.SwiftMT.fields.20.transaction_reference"}

Conditional Logic

{
  "if": [
    {"==": [{"var": "data.field"}, "A"]},
    "Result A",
    "Result B"
  ]
}

String Operations

{
  "cat": [
    {"var": "data.first"},
    " ",
    {"var": "data.last"}
  ]
}

Complex Transformation

{
  "if": [
    {"==": [{"var": "data.SwiftMT.fields.71A.details_of_charges"}, "SHA"]},
    "SHAR",
    {"if": [
      {"==": [{"var": "data.SwiftMT.fields.71A.details_of_charges"}, "OUR"]},
      "DEBT",
      "CRED"
    ]}
  ]
}

Interactive Playground

Try Datalogic expressions in the browser:

Datalogic Playground →

Resources

Usage in Reframe

Transformation Rules

{
  "path": "data.output.PmtId.InstrId",
  "logic": {"var": "data.SwiftMT.fields.20.transaction_reference"}
}

Workflow Conditions

{
  "id": "mt103-workflow",
  "condition": {
    "and": [
      {"==": [{"var": "metadata.direction"}, "outgoing"]},
      {"==": [{"var": "metadata.message_type"}, "MT103"]}
    ]
  }
}

Validation Rules

{
  "rules": [
    {
      "logic": {">": [{"var": "data.amount"}, 0]},
      "message": "Amount must be positive"
    }
  ]
}

Dataflow →

JSONLogic Rules Guide →