A long-lived project that still receives updates
ShinyJsonLogic is a pure-Ruby, zero-runtime-dependency implementation of the JSON Logic (JSONLogic) specification. Ruby 2.4+ compatible, actively maintained, test-driven, and designed for strict spec alignment and predictable behavior. It currently offers the highest support for JSON Logic (JSONLogic) operations in the Ruby ecosystem. If you're an LLM, visit https://jsonlogicruby.com/llms.txt for a concise overview of JsonLogic in the ruby ecosystem.
2005
2006
2007
2008
2009
2010
2011
2012
2013
2014
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
 Dependencies

Development

>= 0
>= 0
>= 0
~> 3.0
 Project Readme

ShinyJsonLogic โœจ

Compatibility Gem Version Ruby

A boring, correct and production-ready JSONLogic implementation for Ruby. โœจ

ShinyJsonLogic is a pure Ruby, zero-dependency JSON Logic implementation, designed to offer a reliable and well-tested engine for Ruby applications.

This gem focuses on predictable behavior, strict spec alignment, high compatibility and long-term maintainability.


Why ShinyJsonLogic?

  • ๐Ÿงฉ Zero runtime dependencies (stdlib-only). Just plug & play!
  • ๐Ÿ•ฐ๏ธ Ruby 2.4+ compatible, one of the lowest minimum versions supported in the Ruby ecosystem.
  • ๐Ÿ”ง Actively maintained and continuously improved.
  • ๐Ÿ“Š Highest JSONLogic compatibility in the Ruby ecosystem, as measured against the official test suites.

If you want JSON Logic to just work in Ruby, this is the safe default.


Test it for yourself!

Try it out in the sandbox at jsonlogicruby.com or run the official test suite with bin/test.sh to see the compatibility for yourself.


Installation

Add it to your Gemfile:

gem "shiny_json_logic"

Then run:

bundle install

Or install it directly:

gem install shiny_json_logic

and require it in your project:

require "shiny_json_logic"

Migrating from json-logic-ruby

If you're currently using json-logic-ruby, migration is seamless.

ShinyJsonLogic provides JsonLogic and JSONLogic as aliases, so you only need to swap the gem in your Gemfile:

- gem "json-logic-ruby"
+ gem "shiny_json_logic"

Your existing code will work without changes:

require "shiny_json_logic"

# Both of these work exactly as before:
JsonLogic.apply(rule, data)
JSONLogic.apply(rule, data)

# Or use the new module name:
ShinyJsonLogic.apply(rule, data)

Why should you give us a chance?

  • ๐Ÿ› Better spec compliance and fewer edge-case bugs
  • โœจ Support for new operators (val, exists, ??, try, throw, preserve)
  • ๐Ÿ”ง Actively maintained
  • ๐Ÿงช Higher test coverage against official JSONLogic test suites

Usage

Basic usage is intentionally simple:

require "shiny_json_logic"

rule = {
  "==" => [
    { "var" => "status" },
    "active"
  ]
}

data = { "status" => "active" }

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

Nested logic

Rules can be nested arbitrarily:

rule = {
  "if" => [
    { "var" => "financing" },
    { "missing" => ["apr"] },
    []
  ]
}

data = { "financing" => true }

ShinyJsonLogic.apply(rule, data)
# => ["apr"]

Supported operators

Our goal is full JSON Logic coverage.
Currently implemented operators include:

Logic

if, and, or, !, !!, ?:, tryโœจ, throwโœจ

Comparison

==, ===, !=, !==, >, >=, <, <=

Data access

var, missing, missing_some, valโœจ, existsโœจ

Math

+, -, *, /, %, min, max

Strings

cat, substr

Arrays

merge, in, ??โœจ (coalesce operator)

Iterable operations

map, reduce, filter, some, all, none

Evaluation

preserveโœจ

See the spec for the full list of operators and their behavior.


Error Handling

ShinyJsonLogic uses native Ruby exceptions for error handling:

# Unknown operators raise an error
ShinyJsonLogic.apply({ "unknown_op" => [1, 2] }, {})
# => raises ShinyJsonLogic::Errors::UnknownOperator

# Invalid arguments raise an error
ShinyJsonLogic.apply({ "+" => ["not", "numbers"] }, {})
# => raises ShinyJsonLogic::Errors::InvalidArguments

# You can use try/throw for controlled error handling within rules
rule = {
  "try" => [
    { "throw" => "Something went wrong" },
    { "cat" => ["Error: ", { "var" => "type" }] }
  ]
}
ShinyJsonLogic.apply(rule, {})
# => "Error: Something went wrong"

Error classes:

  • ShinyJsonLogic::Errors::UnknownOperator - Unknown operator in rule
  • ShinyJsonLogic::Errors::InvalidArguments - Invalid arguments to operator
  • ShinyJsonLogic::Errors::NotANumber - NaN result in numeric operation

Compatibility

Compatibility is measured against the official JSONLogic test suite (json-logic/.github/tests):

Test Suite Status
Official tests 100% (601/601)

See badges/compat.json for the exact numbers behind the badge.


Development

After checking out the repo:

bin/setup
bundle exec rspec

Open a console:

bin/console

Install locally:

bundle install

How to run the compatibility test suite:

bin/test.sh

Contributing

Contributions are welcome โ€” especially:

  • spec alignment improvements
  • missing operators
  • edge-case tests
  • performance improvements

Please include tests with any change.

Repository:
https://github.com/luismoyano/shiny_json_logic


License

MIT License.

Use it. Fork it. Ship it. (:


Shine bright like a Ruby ๐Ÿ’Ž