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

get_concurrent values #930

wants to merge 2 commits into from

Conversation

KM8Oz
Copy link

@KM8Oz KM8Oz commented Sep 11, 2022

/// 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(&self, list: &str) -> 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)
    }

@kangalio
Copy link

I suspect this won't be merged as-is. It is a rather opinionated feature for such a fundamental crate.

Also, it's not ready needed: object["A"]["B"]["C"] works.

@KM8Oz
Copy link
Author

KM8Oz commented May 23, 2023 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants