ksql 0.3.1

A JSON data expression lexer, parser, cli and library
Documentation

ksql   Latest Version

Is a JSON data expression lexer, parser, cli and library.

How to install CLI

~ cargo install ksql

Usage

use ksql::parser::{Parser, Value};
use std::error::Error;

fn main() -> Result<(), Box<dyn Error>>{
    let src = r#"{"name":"MyCompany", "properties":{"employees": 50}"#.as_bytes();
    let expression = ".properties.employees > 20";
    let ex = Parser::parse(expression.as_bytes())?;
    let result = ex.calculate(src)?;
    assert_eq!(Value::Bool(true), result);
    Ok(())
}

CLI Usage

~ ksql '(.field1 + 1) /2' '{"field1": 1}'
or
echo '{"field1": 1}' | ksql '(.field1 + 1) /2'

Expressions

Expressions support most mathematical and string expressions see below for details:

Syntax & Rules

Token Example Syntax Rules
Equals == supports both == and =.
Add + N/A
Subtract - N/A
Multiply * N/A
Divide / N/A
Gt > N/A
Gte >= N/A
Lt < N/A
Lte <= N/A
OpenParen ( N/A
CloseParen ) N/A
OpenBracket [ N/A
CloseBracket ] N/A
Comma , N/A
QuotedString "sample text" Must start and end with an unescaped " character
Number 123.45 Must start and end with a valid 0-9 digit.
BoolenTrue true Accepts true as a boolean only.
BoolenFalse false Accepts false as a boolean only.
Identifier .identifier Starts with a . and ends with whitespace blank space. This crate currently uses gjson and so the full gjson syntax for identifiers is supported.
And && N/A
Not ! Must be before Boolean identifier or expression or be followed by an operation
Or || N/A
Contains CONTAINS Ends with whitespace blank space.
In IN Ends with whitespace blank space.
StartsWith STARTSWITH Ends with whitespace blank space.
EndsWith ENDSWITH Ends with whitespace blank space.
NULL NULL N/A

License