JSON Logic is a format for encoding business rules as JSON objects. It provides a portable, language-agnostic way to define logic that can be evaluated consistently across different platforms—whether in Ruby on the server, JavaScript in the browser, or any other language with a JSON Logic implementation.
Structure
A JSON Logic rule is a JSON object with a single key (the operator) and a value (the arguments):
{ "operator": [argument1, argument2, ...] }
Rules can be nested—any argument can itself be another rule, allowing you to build complex expressions from simple primitives.
Data
Rules are evaluated against a data object. Use the val
operator to access values from this data:
Shiny JSON Logic
shiny_json_logic is a Ruby gem that implements the JSON Logic specification
with up-to-date operators. It's designed to be safe, simple and easy to use.
require 'shiny_json_logic'
rule = { ">" => [{ "val" => "age" }, 18] }
data = { "age" => 25 }
ShinyJsonLogic.apply(rule, data) # => true
# Aliases for easier migration from other gems
JsonLogic.apply(rule, data) # => true
JSONLogic.apply(rule, data) # => true
Why Shiny JSON Logic?
There are other JSON Logic implementations in Ruby, but they have limitations:
| Feature | shiny_json_logic | json_logic | json-logic-rb | json_logic_ruby |
|---|---|---|---|---|
| Compatibility | 99.7% | 63.9% | 67.7% | 42.3% |
| Last updated | 2026 | 2020 | 2025 | 2024 |
| Ruby 2.x | ✓ | ✓ | ✗ | ✗ |
| Ruby 3.x | ✓ | ✗ | ✓ | ✓ |
| Ruby 4.x | ✓ | ✗ | ? | ? |
| val operator | ✓ | ✗ | ✗ | ✗ |
| try / throw | ✓ | ✗ | ✗ | ✗ |
| ?? (nullish coalescing) | ✓ | ✗ | ✗ | ✗ |
| exists operator | ✓ | ✗ | ✗ | ✗ |
| Scope navigation in iterators | ✓ | ✗ | ✗ | ✗ |
| Actively maintained | ✓ | ✗ | ✓ | ✗ |