New Research: Supply Chain Attack on Axios Pulls Malicious Dependency from npm.Details →
Socket
Book a DemoSign in
Socket

json-cnf

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

json-cnf

Functions for filtering SQL-like json with conjunctive normal form filters

latest
Source
npmnpm
Version
0.0.8
Version published
Maintainers
1
Created
Source

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)

Keywords

json

FAQs

Package last updated on 10 Feb 2019

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts