Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

get_concurrent values #930

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
21 changes: 20 additions & 1 deletion src/value/mod.rs
Expand Up @@ -304,7 +304,26 @@ impl Value {
pub fn get<I: Index>(&self, index: I) -> Option<&Value> {
index.index_into(self)
}


/// Similar to `get` method but fast to get deep json Value
/// ```
/// # use serde_json::json;
///
/// let object = json!({ "A": { "B": { "C": "foo" } } }); // true
///
/// assert_eq!(*array.get_concurrent("A.B.C").unwrap(), json!("foo")); // true
/// assert_eq!(*array.get_concurrent("A.B.C.D").unwrap(), json!("foo")); // true also
/// ```
pub fn get_concurrent<I: &str>(&self, pattern: I) -> Option<Value> {
let rest: Value = Value::default();
for item in list.split(".").into_iter() {
let rest = match self.0.get(item) {
Some(m) => Some(m),
None => Some(&self.0),
};
}
Some(rest)
}
/// Mutably index into a JSON array or map. A string index can be used to
/// access a value in a map, and a usize index can be used to access an
/// element of an array.
Expand Down