Function gjson::get[][src]

pub fn get<'a>(json: &'a str, path: &'a str) -> Value<'a>
Expand description

Searches json for the specified path. A path is in dot syntax, such as “name.last” or “age”. When the value is found it’s returned immediately.

A path is a series of keys separated by a dot. A key may contain special wildcard characters ‘*’ and ‘?’. To access an array value use the index as the key. To get the number of elements in an array or to access a child path, use the ‘#’ character. The dot and wildcard character can be escaped with ’'.

{
  "name": {"first": "Tom", "last": "Anderson"},
  "age":37,
  "children": ["Sara","Alex","Jack"],
  "friends": [
    {"first": "James", "last": "Murphy"},
    {"first": "Roger", "last": "Craig"}
  ]
}
 "name.last"          >> "Anderson"
 "age"                >> 37
 "children"           >> ["Sara","Alex","Jack"]
 "children.#"         >> 3
 "children.1"         >> "Alex"
 "child*.2"           >> "Jack"
 "c?ildren.0"         >> "Sara"
 "friends.#.first"    >> ["James","Roger"]

This function expects that the json is valid, and does not validate. Invalid json will not panic, but it may return back unexpected results. If you are consuming JSON from an unpredictable source then you may want to use the valid function first.