JMESPath Community is the community implementation of JMESPath, a query and transformation language for JSON.
Evaluating JMESPath Expression
Use the search function to evaluate a JMESPath expression.
Example
use jmespath_community as jmespath;
use ;
// Parse some JSON data into a JMESPath variable
let json_str = "{\"foo\":{\"bar\":{\"baz\":true}}}";
let data = from_json.unwrap;
let result = search.unwrap;
assert_eq!;
A JMESPath expression can be parsed once and evaluated multiple times using the parse function.
Example
use jmespath_community as jmespath;
use ;
let ast = parse.unwrap;
let data = from_json.unwrap;
let result = ast.search.unwrap;
assert_eq!;
Registering Custom Functions
JMESPath Community comes with a host of useful builtin functions. However, it can be extended with third-party functions.
Example
Create a new instance of the JMESPath Runtime object and register your custom function:
Example
use jmespath_community as jmespath;
use jmespath::FunctionRegistrar;
use jmespath::{Runtime, Value};
let add = Box::new(custom_functions::add::new());
let mut runtime = Runtime::create_runtime();
runtime.register(add);
let expression = "foo";
let root = Value::Null;
let result = runtime.search(expression, &root).unwrap();
assert_eq!(None, result);