0.0.9 • Published 4 years ago

artista-jql v0.0.9

Weekly downloads
3
License
ISC
Repository
github
Last release
4 years ago

artista-jql

Query language for JSON

Installation

$ npm install artista-jql

Browser

<script src="..../jql/dist/jql.js"></script>

node.js

const JQL = require('..../jql/dist/jql.js').JQL;

Quick Start

Filter following JSON data.

const items = [
  {
    id: 1,
    kb: true,
    foo: {
        bar: "FOO"
    }
  },
  {
    id: 2,
    kb: false,
    foo: {
        bar: "FOO"
    }
  },
  {
    id: 3,
    kb: false,
    foo: {
        bar: "BAR"
    }
  }
];

Query sample 1

const query = "kb = false";
const filteredItems = JQL.filter(query, items);

Return filtered items.

[
  {
    id: 2,
    kb: false
  },
  {
    id: 3,
    kb: false
  }
];

Query sample 2

const query = 'foo.bar = "BAR"';
const filteredItems = JQL.filter(query, items);

Return filtered items.

[
  {
    id: 3,
    kb: false
  }
];

Grammar

Supported data types for right value

typeexample
String"foo", "bar", ...
Number1, 200, -15, 14.5, ...
Booleantrue false

Logical Operators (case insensitive)

operatordescription
ANDlogical conjunction
ORlogical sum
!logical negation

Comparison Operators (case insensitive)

operatordescription
=equal
!=not equal
>=greater than or equal to
<=less than or equal to
>greater than
<less than
CONTAINSCheck if right value contains left value when right value is StringOr check if right value is in left array when left value is Array

Query examples

sample queriesdescription
Goodname = "hoge"compare String
Goodname contains "eorg"partial match with String
Goodage = 37, age < 30, age >= 3compare Number
Goodflag = truecompare Boolean
Goodname != "George"not equal
Goodperson.age > 40JSON dot notation
Goodk1 = "v1" AND k2 = "v2"AND operator
Goodk1 = "v1" OR k2 = "v2"OR operator
Goodk1 = "v1" AND k2 = "v2" ... AND kx= "vx"multiple AND/OR operator
BADk1 = "v1" AND k2 = "v2" OR k3 = "v3"mixed logical operators
Good! (name contains "eorg")! operator
Good(a = 1 AND b = 'foo') OR c = falsewith brackets
Good(a = 1 OR b = 'foo') AND c = falsewith brackets
Good(a = 1 OR b = 'foo') AND (c = false AND d CONTAINS 'bar')with brackets
BAD((a = 1 AND b = 'foo') OR c = false) AND d CONTAINS 'bar'nested brackets
0.0.9

4 years ago

0.0.8

4 years ago

0.0.7

4 years ago

0.0.6

4 years ago

0.0.5

4 years ago

0.0.3

4 years ago

0.0.4

4 years ago

0.0.2

4 years ago

0.0.1

4 years ago