#json #query #jmespath

nightly jmespath-macros

Statically compiles JMESPath expressions

2 releases

Uses old Rust 2015

0.1.1 Aug 26, 2017
0.1.0 Dec 16, 2016

#521 in #query

MIT license

16KB
322 lines

jmespath-macros

The jmespath-macros crate provides the jmespath! macro used to statically compile JMESPath expressions.

By statically compiling JMESPath expressions, you pay the cost of parsing and compiling JMESPath expressions at compile time rather than at runtime, and you can be sure that the expression is valid if your program compiles.

Note: This only works with a nightly compiler.

#![feature(plugin)]

#![plugin(jmespath_macros)]
extern crate jmespath;

fn main() {
    // Create our statically compiled expression. The build will fail
    // if the expression is invalid.
    let expr = jmespath!("foo.bar");

    // Parse some JSON data into a JMESPath variable
    let json_str = r#"{"foo": {"bar": true}}"#;
    let data = jmespath::Variable::from_json(json_str).unwrap();
    let result = expr.search(data).unwrap();
    assert_eq!(true, result.as_boolean().unwrap());
}

lib.rs:

This crate provides the jmespath! macro used to statically compile JMESPath expressions.

By statically compiling JMESPath expressions, you pay the cost of parsing and compiling JMESPath expressions at compile time rather than at runtime, and you can be sure that the expression is valid if your program compiles.

Note: This only works with a nightly compiler.

#![feature(plugin)]

#![plugin(jmespath-macros)]
extern crate jmespath;

fn main() {
    // Create our statically compiled expression. The build will fail
    // if the expression is invalid.
    let expr = jmespath!("foo.bar");

    // Parse some JSON data into a JMESPath variable
    let json_str = "{\"foo\":{\"bar\":true}}";
    let data = jmespath::Variable::from_json(json_str).unwrap();
    let result = expr.search(data).unwrap();
    assert_eq!(true, result.as_boolean().unwrap());
}

Dependencies