A JSON Predicate implementation in accordance to the Snell RFC draft.
Let us consider the following predicate.
predicate = %{
op: "and",
path: "/b",
apply: [
%{
op: "less",
value: 3
},
%{
op: "more",
value: 5
},
%{
op: "type",
value: "integer"
}
]
}
In order to validate this against a structure, a boolean function can be generated as follows.
fun = Snell.parse(predicate)
Once we have this, we can proceed to verify whether a struct suffices the given predicate.
struct = %{
b: 4
}
fun.(struct)
Do notice though that type
values are Elixir types, and
thus not necessarily JavaScript types.
This library was developed for use under the
Mineteria framework.
However, it was decided to be released onto the public domain. Thanks!