sonic_rs

Macro pointer

Source
macro_rules! pointer {
    () => { ... };
    ($($x:expr),+ $(,)?) => { ... };
}
Expand description

Represents a json pointer path.

Used to indexing a Value, LazyValue, get or get_unchecked.

The path can includes both keys or indexes.

  • keys: string-like, used to indexing an object.
  • indexes: usize-like, used to indexing an array.

ยงExamples

use sonic_rs::JsonValueTrait;

let value: sonic_rs::Value = sonic_rs::from_str(
    r#"{
    "foo": [
       0,
       1,
       {
         "bar": 123
       }
     ]
}"#,
)
.unwrap();
let path = pointer!["foo", 2, "bar"];

let got = value.pointer(&path).unwrap();

assert_eq!(got, 123);