forked from RedisJSON/RedisJSON
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.rs
42 lines (38 loc) · 1.07 KB
/
main.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
/*
* Copyright Redis Ltd. 2016 - present
* Licensed under your choice of the Redis Source Available License 2.0 (RSALv2) or
* the Server Side Public License v1 (SSPLv1).
*/
mod json_node;
mod json_path;
mod select_value;
use serde_json::Value;
use std::env;
use std::process;
fn main() {
let args: Vec<String> = env::args().collect();
if args.len() != 3 {
println!("usage: json_path_tests <json> <path>");
process::exit(1);
}
let json = &args[1];
let json_path = &args[2];
let query = json_path::compile(json_path);
if let Err(e) = query {
println!("Failed parsing json path, {}", e);
process::exit(1);
}
let query = query.unwrap();
let v = serde_json::from_str(json);
if let Err(e) = v {
println!("Failed parsing json, {}", e);
process::exit(1);
}
let v: Value = v.unwrap();
let path_calculator =
json_path::PathCalculator::<json_path::DummyTrackerGenerator>::create(&query);
let res = path_calculator.calc(&v);
for r in res {
println!("{}", r);
}
}