Skip to content

Latest commit

 

History

History
25 lines (17 loc) · 1.18 KB

README.md

File metadata and controls

25 lines (17 loc) · 1.18 KB

json-logic-hs

This parser accepts JsonLogic rules and executes them in Haskell

This is a Haskell porting of the excellent GitHub project by jwadhams for JavaScript: json-logic-js.

All credit goes to him, this is simply an implementation of the same logic in Haskell (small differences below).

The JsonLogic format is designed to allow you to share rules (logic) between front-end and back-end code (regardless of language difference), even to store logic along with a record in a database. JsonLogic is documented extensively at JsonLogic.com, including examples of every supported operation and a place to try out rules in your browser.

The same format can also be executed in PHP by the library json-logic-php

Examples

Simple

import JsonLogic
import Data.Aeson as A
import qualified Data.Aeson.QQ.Simple as AQ

test :: IO ()
test = do
  let tests = [AQ.aesonQQ|{ "==": [1,1]}|]
  let data_ = A.Null
  print $ jsonLogic tests data_