sonic_rs::lazyvalue

Function get_many

Source
pub fn get_many<'de, Input>(
    json: Input,
    tree: &PointerTree,
) -> Result<Vec<LazyValue<'de>>>
where Input: JsonInput<'de>,
Expand description

get_many returns multiple fields from the PointerTree.

The result is a Result<Vec<LazyValue>>. The order of the Vec is same as the order of the tree.
If json is invalid, or the field not be found, it will return a err.

ยงExamples

use sonic_rs::pointer;
let json = r#"
    {"u": 123, "a": {"b" : {"c": [null, "found"]}}}"#;
// build a pointer tree, representing multiple json path
let mut tree = sonic_rs::PointerTree::new();
tree.add_path(&["u"]);
tree.add_path(&pointer!["a", "b", "c", 1]);
let nodes = sonic_rs::get_many(json, &tree).unwrap();
// the node order is as the order of `add_path`
assert_eq!(nodes[0].as_raw_str(), "123");
assert_eq!(nodes[1].as_raw_str(), "\"found\"");