# `AshBackendDrivenOptimisticUi.JsonLogic`
[🔗](https://github.com/Undeadlol1/ash_backend_driven_optimistic_ui/blob/v0.1.0/lib/ash_backend_driven_optimistic_ui/json_logic.ex#L1)

Evaluates JSON Logic the way the client does: the full standard (`var`,
`missing`, `missing_some`, `if`, `?:`, `== != === !==`, `! !!`, `or`, `and`,
`> >= < <=` including the three-operand "between" form, `max`, `min`,
`+ - * / %`, `map`, `filter`, `reduce`, `all`, `none`, `some`, `merge`, `in`,
`cat`, `substr`, `log`), checked against the official JSON Logic test suite,
plus five custom operations: `has` (whether a dotted path's last key is
present, even with a null value), `abs`, `round` (one or two operands, half
away from zero), `to_string` (`nil` becomes empty text) and `now` (the
current UTC time as ISO 8601 text). Literals pass through and a list that is
not an operation evaluates each element.

Where JavaScript would produce `NaN`, which JSON cannot carry, this raises
`ArgumentError` instead: arithmetic (`+ - * / % min max abs round`) accepts
only numbers and numeric strings. An unknown operation, or a map holding more
than one operation, raises too. Comparison with `<`, `>`, `<=` and `>=` never
raises: two texts compare as text, anything else compares as numbers, and a
side that is not numeric makes the result `false`.

`cat` prints `nil` as `null` and a whole float without its fraction.

# `run`

```elixir
@spec run(term(), term()) :: term()
```

Evaluates `rule` against `data`, a map with string keys.

# `truthy?`

```elixir
@spec truthy?(term()) :: boolean()
```

JSON Logic truthiness: everything but `false`, `nil`, `0`, `""` and `[]`.

---

*Consult [api-reference.md](api-reference.md) for complete listing*
