Function sonic_rs::get_from_bytes
source · pub fn get_from_bytes<Path: IntoIterator>(
json: &Bytes,
path: Path
) -> Result<LazyValue<'_>>Expand description
Gets a field from a path. And return it as a Result<LazyValue>.
If not found, return an error. If the path is empty, return the whole JSON as a LazyValue.
The Item of the path should implement the Index trait.
Examples
use bytes::Bytes;
let bs = Bytes::from(r#"{"a": 1}"#);
let lv = get_from_bytes(&bs, &["a"]).unwrap();
assert_eq!(lv.as_raw_str(), "1");
/// not found the field "a"
let lv = get_from_bytes(&bs, &["b"]);
assert!(lv.is_err());