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.
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.
Add JSONLogic to your Ruby project in minutes
Add shiny_json_logic to your Gemfile
(
See on GitHub)
:
gem 'shiny_json_logic'
Then run:
$ bundle install
Evaluate rules with data:
require 'shiny_json_logic'
rule = { ">" => [{ "var" => "age" }, 18] }
data = { "age" => 21 }
ShinyJsonLogic.apply(rule, data)
# => true
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!
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.
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.
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.
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.
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.
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.