Run this notebook

Use Livebook to open this notebook and explore new ideas.

It is easy to get started, on your machine or the cloud.

Click below to open and run it in your Livebook at .

(or change your Livebook location)

# Judge Json ```elixir Mix.install([ {:rulex, ">= 1.0.0"} ]) ``` ## Quick Start Example You can pass a big json paylaod: ```elixir payload = to_string(~c" { \"data\": { \"person\": { \"name\": \"Lionel\", \"last_name\": \"Messi\", \"interests\": [ \"soccer\", \"hot dogs\", \"sports\" ] } }, \"rules\": [ { \"id\": \"123456\", \"conditions\": { \"all\": [ { \"path\": \"/person/name\", \"operator\": \"equals\", \"value\": \"Lionel\" }, { \"path\": \"/person/last_name\", \"operator\": \"like\", \"value\": \"mess\" }, { \"path\": \"/person/interests\", \"operator\": \"contains\", \"value\": \"soccer\" } ] }, \"action\": \"collect_signature.exs\" } ] }") IO.puts("Your matched rules are:") results = Rulex.evaluate(payload) ``` You can also split the data and rules up like: ```elixir data = to_string(~c"{ \"source\": \"Microsoft\", \"product\": \"ms_product\", \"data\": { \"msg\": \"xyz happened\" } }") rules = to_string(~c"[ { \"id\": \"MS_RULE_123\", \"conditions\": { \"all\": [ { \"path\": \"/source\", \"operator\": \"equals\", \"value\": \"Microsoft\" }, { \"path\": \"/data/msg\", \"operator\": \"like\", \"value\": \"XYZ\" } ] }, \"action\": \"handle_XYZ\" } ]") IO.puts("Your matched rules are:") results = Rulex.evaluate(data, rules) ``` You can also pass plain Elixir like: ```elixir data = %{"message" => ["one", "two", "three"]} rules = [ %{ "id" => "test_rule", "conditions" => %{ "any" => [ %{ "path" => "/message", "operator" => "contains", "value" => "four" }, %{ "path" => "/message", "operator" => "contains", "value" => "two" } ] }, "action" => "run some handler code" } ] IO.puts("Your matched rules are:") results = Rulex.evaluate(data, rules) ```
See source

Have you already installed Livebook?

If you already installed Livebook, you can configure the default Livebook location where you want to open notebooks.
Livebook up Checking status We can't reach this Livebook (but we saved your preference anyway)
Run notebook

Not yet? Install Livebook in just a minute

Livebook is open source, free, and ready to run anywhere.

Run on your machine

with Livebook Desktop

Run in the cloud

on select platforms

To run on Linux, Docker, embedded devices, or Elixir’s Mix, check our README.

PLATINUM SPONSORS
SPONSORS
Code navigation with go to definition of modules and functions Read More ×