serde_json_traversal

Crates.ioserde_json_traversal
lib.rsserde_json_traversal
version0.2.0
sourcesrc
created_at2020-08-16 03:51:05.709622
updated_at2021-08-12 22:34:02.285168
descriptionA macro that creates the boilerplate to traverse JSON (js/ts style)
homepagehttps://github.com/cecton/serde_json_traversal
repositoryhttps://github.com/cecton/serde_json_traversal
max_upload_size
id277122
size18,019
Cecile Tonglet (cecton)

documentation

README

Synopsis

use serde_json_traversal::serde_json_traversal;

#[test]
fn success() {
    let json_obj = serde_json::json!({
        "foo": "bar",
        "bar": [
            "foo",
            "baz",
        ],
        "baz": {
            "foo": [
                "bar",
                {
                    "bar": "baz",
                },
            ],
        },
    });

   assert_eq!(serde_json_traversal!(json_obj => foo).unwrap(), "bar");
   assert_eq!(serde_json_traversal!(json_obj => bar => [0]).unwrap(), "foo");
   assert_eq!(serde_json_traversal!(json_obj => baz => foo => [0]).unwrap(), "bar");
   assert_eq!(serde_json_traversal!(json_obj => baz => foo => [1] => bar).unwrap(), "baz");

   let json_arr = serde_json::json!([
        "foo",
        {
            "bar": "baz",
        }
   ]);

   assert_eq!(serde_json_traversal!(json_arr => [0]).unwrap(), "foo");
   assert_eq!(serde_json_traversal!(json_arr => [1] => bar).unwrap(), "baz");
}
Commit count: 3

cargo fmt