JSONLogic Ruby Shiny JSON Logic

JSONLogic Ruby JSONLogic in Ruby

Write your business rules in JSON, run them anywhere

The fastest and most compliant JSON Logic engine for Ruby. Beats all the other options both in speed and reliability. Built by contributors to the JSON Logic specification for your Ruby projects.

Rule (JSON Logic) logic
Data (JSON) input
Ruby (shiny_json_logic) server-side
Hit Evaluate to check the result
JavaScript (json-logic-engine) client-side
Hit Evaluate to check the result

What's happening?

The same rule and data are evaluated by two different engines simultaneously. Ruby runs server-side using shiny_json_logic, JavaScript runs client-side using json-logic-engine. This demonstrates that JSON Logic rules are truly portable across platforms.

Get Started

Add JSONLogic to your Ruby project in minutes

1

Install

Add shiny_json_logic to your Gemfile ( See on GitHub) :

Gemfile
gem 'shiny_json_logic'

Then run:

Terminal
$ bundle install
2

Use

Evaluate rules with data:

app.rb
require 'shiny_json_logic'

rule = { ">" => [{ "var" => "age" }, 18] }
data = { "age" => 21 }

ShinyJsonLogic.apply(rule, data)
# => true

Why Shiny JSON Logic?

Easy! Shiny is the most compliant and also the fastest Ruby gem to run JSON Logic. We're long time fans who started this project out of frustration by the broken or abandoned gems we always had to deal with in our projects. Does this sound familiar to you? Say no more!

Feature shiny_json_logic json_logic json-logic-rb json_logic_ruby
Official tests 100% 63.9% 93.68% 42.3%
Avg. ops/s 🏆 >100k ~55k ~40k ~45k
Last updated 2026 2020 2026 2024
Ruby 2.x
Ruby 3.x
Ruby 4.x
Handles truthiness correctly
Zero dependencies
Actively maintained

This gem is built by maintainers and active contributors in the JSON Logic community where we help with defining the specification itself. We don't just copy tests, we write them. So if you want to use JSON Logic in your Ruby projects, give Shiny a try and see the difference!

The JSON Logic Specification

A portable way to write business rules

The JSON Logic specification defines a standard format for expressing conditional logic as JSON. Created by Jeremy Wadhams, it enables you to write rules once and evaluate them identically across JavaScript, Ruby, Python, PHP, and many other languages.

The specification is now maintained by the json-logic community on GitHub and we make sure to test shiny against the official test suite to ensure compliance. As of now, we are the only implementation that passes 100% of the official tests.

Frequently Asked Questions

What is JSON Logic?

JSON Logic is a way to write business rules as JSON objects that can be evaluated consistently across different platforms. Instead of writing code like age >= 21, you write {">=": [{"var": "age"}, 21]}. This lets you store rules in a database, share them between frontend and backend, or let non-developers create rules through a UI.

Is JSON Logic safe to evaluate user input?

Yes. JSON Logic is designed to be safe for untrusted input. Unlike eval(), it can only perform the operations defined in the spec—no file access, no network calls, no arbitrary code execution. You control what data the rules can access, and the operations are pure functions with no side effects.

What can I build with JSON Logic?

Common use cases include feature flags (targeting rules for which users see what), access control (role-based permissions), dynamic pricing (discount eligibility), form validation (conditional field requirements), and eligibility engines (loan approvals, insurance quotes). Basically anything where business rules need to change without code deploys.

Does JSON Logic work the same in Ruby and JavaScript?

That's the whole point—but only if your implementation is spec-compliant. Other Ruby gems have bugs that make rules behave differently than in JavaScript. shiny_json_logic passes 100% of the official JSON Logic tests, so you can trust that a rule tested in the browser will work identically in your Ruby backend. That's why we built this playground to show both engines side by side.

Why choose shiny_json_logic over other Ruby gems?

Spec compliance AND speed: shiny_json_logic is the only Ruby gem that passes 100% of the official JSON Logic tests and also the fastest Ruby JSON Logic gem — winning across all the benchmark runs across every Ruby version tested (up to 117% faster depending on version). Are you using many config files? If your business logic files are really long or you have lots of rules and users, then shiny_json_logic is the best choice for you.