json-cnf
v0.0.8
Published
Functions for filtering SQL-like json with conjunctive normal form filters
Downloads
24
Maintainers
Readme
JSON-CNF
What is CNF?
CNF is short for Conjunctive Normal Form, which is a way of arranging logical arguments into groups of logical OR statements between AND statements, e.g.
(statement_{1,1} OR, .... statement_{1,i})
AND
(statement_{2,1} OR, .... statement_{2,j})
AND
...
AND
(statement_{x,1} OR, .... statement_{x,k})
Assuming your JSON data is in an SQL-like format:
{
recordID_1: {
column1: value,
column2: value,
...,
columnN: value
},
...,
recordID_M: {
column1: value,
column2: value,
...,
columnN: value
}
}
This library allows you to easily apply a list of filters in CNF to your JSON to find which records pass the filters.
There are two main functions:
- groupByConjunctiveNormalForm: takes a list of filters and returns arranges them in CNF
- filterJSON: takes your JSON and a list of filters and applies the CNF grouping of those filters to the JSON
What's a filter
A filter consists of five parts:
- logic: AND or OR (defaults to AND)
- function: applied to the value of the field prior to the comparisons (defaults to the identity function)
- conditional: a logical test (defaults to equality)
- field: a field in your records
- input: what the value should be compared to
thus a filter is applied to a record as so:
conditional(function(record[field]), input)