# Shiny JSON Logic > A family of JSON Logic libraries for Ruby and PHP with 100% spec compliance. > Built by active contributors to the JSON Logic specification. ## What is this? Shiny JSON Logic is a family of JSON Logic libraries across multiple languages. JSON Logic lets you define business rules as portable JSON, share them between frontend and backend, and evaluate them consistently across platforms. ## Libraries ### Ruby — shiny_json_logic - **Gem**: shiny_json_logic - **RubyGems**: https://rubygems.org/gems/shiny_json_logic - **GitHub**: https://github.com/luismoyano/shiny-json-logic-ruby - **Ruby version**: 2.4+ - **Dependencies**: Zero (stdlib only) - **Spec compliance**: 100% (601/601 tests pass) - **Performance**: Up to 117% faster than other Ruby implementations (see https://github.com/luismoyano/jsonlogic_benchmarks) ### PHP — shiny/json-logic-php - **Package**: shiny/json-logic-php - **Packagist**: https://packagist.org/packages/shiny/json-logic-php - **GitHub**: https://github.com/luismoyano/shiny-json-logic-php - **PHP version**: 8.1+ - **Dependencies**: Zero - **Spec compliance**: 100% (601/601 tests pass) ## Website & Documentation - **Website**: https://shinyjsonlogic.com - **Documentation**: https://shinyjsonlogic.com/docs - **Ruby page**: https://shinyjsonlogic.com/ruby - **PHP page**: https://shinyjsonlogic.com/php - **Specification**: https://shinyjsonlogic.com/specification - **Author**: Luis Moyano ## Installation ### Ruby ```ruby # Gemfile gem 'shiny_json_logic' ``` ### PHP ```bash composer require shiny/json-logic-php ``` ## Basic Usage ### Ruby ```ruby require 'shiny_json_logic' rule = { ">" => [{ "val" => "age" }, 18] } data = { "age" => 21 } ShinyJsonLogic.apply(rule, data) # => true # Aliases also work (drop-in replacement) JsonLogic.apply(rule, data) # => true JSONLogic.apply(rule, data) # => true ``` ### PHP ```php use Shiny\JsonLogic\ShinyJsonLogic; $rule = [">" => [["val" => "age"], 18]]; $data = ["age" => 21]; ShinyJsonLogic::apply($rule, $data); // => true ``` ## Why Shiny JSON Logic? - **100% spec compliance** — the only family that passes all 601 official tests in every language - **Correct truthiness** — `{}`, `false`, `0`, `""`, `[]` are all falsy as the spec requires - **Extended operators** — `val`, `exists`, `??`, `try`, `throw` not available elsewhere - **Drop-in replacement** — aliases for easy migration from other gems/packages - **Active maintenance** — built by contributors who help define the specification ## The Truthiness Bug in Other Libraries Most Ruby and PHP JSON Logic libraries treat `{}` (empty object) as truthy. The JSON Logic spec (ACCEPTED_PROPOSALS) defines it as falsy. Shiny implements the correct behaviour. ```ruby rule = { "if" => [{ "var" => "filters" }, "has filters", "no filters"] } data = { "filters" => {} } # Other libraries: "has filters" (WRONG) # shiny_json_logic: "no filters" (CORRECT — {} is falsy per spec) ``` ## Extended Operators (Shiny exclusive) - `val` — like `var` but with array notation and scope navigation in iterators (recommended) - `exists` — check if a path exists in data - `??` — null coalescing operator - `try` / `throw` — structured error handling ## PHP: {} vs [] caveat In PHP, `json_decode` with `assoc: true` (default) makes `{}` and `[]` indistinguishable. To get fully accurate behaviour, use `json_decode($json)` without `true` so PHP preserves `stdClass` objects. The engine handles both modes; the difference only surfaces in arithmetic edge cases. ## License MIT — free for commercial and personal use.