1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
use Value;
/// A type that can be used to index into a `serde_json_borrow::Value`.
///
/// [`get`] of `Value` accept any type that implements `Index`. This
/// trait is implemented for strings which are used as the index into a JSON
/// map, and for `usize` which is used as the index into a JSON array.
///
/// [`get`]: ../enum.Value.html#method.get
///
/// This trait is sealed and cannot be implemented for types outside of
/// `serde_json_borrow`.
/// # Examples
///
/// ```
/// # use serde_json_borrow::Value;
/// #
/// let json_obj = r#"
/// {
/// "x": {
/// "y": ["z", "zz"]
/// }
/// }
/// "#;
///
/// let data: Value = serde_json::from_str(json_obj).unwrap();
///
/// assert_eq!(data.get("x").get("y").get(0), &Value::Str(std::borrow::Cow::Borrowed("z")));
/// assert_eq!(data.get("x").get("y").get(1), &Value::Str(std::borrow::Cow::Borrowed("zz")));
/// assert_eq!(data.get("x").get("y").get(2), &Value::Null);
///
/// assert_eq!(data.get("a"), &Value::Null);
/// assert_eq!(data.get("a").get("b"), &Value::Null);
/// ```