File: serde.rs

package info (click to toggle)
rust-serde-json-path 0.7.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 680 kB
  • sloc: makefile: 2
file content (17 lines) | stat: -rw-r--r-- 458 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
use serde::Deserialize;
use serde_json::{from_value, json};
use serde_json_path::JsonPath;

#[derive(Deserialize)]
struct Config {
    pub path: JsonPath,
}

#[test]
fn can_deserialize_json_path() {
    let config_json = json!({ "path": "$.foo.*" });
    let config = from_value::<Config>(config_json).expect("deserializes");
    let value = json!({"foo": [1, 2, 3]});
    let nodes = config.path.query(&value).all();
    assert_eq!(nodes, vec![1, 2, 3]);
}