#serde-json #create #traversal #style #boilerplate #js-ts #macro

serde_json_traversal

A macro that creates the boilerplate to traverse JSON (js/ts style)

2 unstable releases

0.2.0 Aug 12, 2021
0.1.0 Aug 16, 2020

#1050 in Encoding

Download history 689/week @ 2024-07-21 504/week @ 2024-07-28 423/week @ 2024-08-04 583/week @ 2024-08-11 185/week @ 2024-08-18 588/week @ 2024-08-25 325/week @ 2024-09-01 113/week @ 2024-09-08 106/week @ 2024-09-15 163/week @ 2024-09-22 128/week @ 2024-09-29 77/week @ 2024-10-06 140/week @ 2024-10-13 202/week @ 2024-10-20 26/week @ 2024-10-27 51/week @ 2024-11-03

426 downloads per month

MIT/Apache

7KB

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");
}

No runtime deps