json icon indicating copy to clipboard operation
json copied to clipboard

get_concurrent values

Open KM8Oz opened this issue 1 year ago • 2 comments

/// 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)
    }

KM8Oz avatar Sep 11 '22 18:09 KM8Oz

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.

kangalio avatar May 23 '23 18:05 kangalio

I made some changes on it so it will fit my needs. Thanks overall

On Tue, May 23, 2023, 19:28 kangalio @.***> wrote:

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.

— Reply to this email directly, view it on GitHub https://github.com/serde-rs/json/pull/930#issuecomment-1559944100, or unsubscribe https://github.com/notifications/unsubscribe-auth/ABKPIGZMNNOIJH3MFGYTD53XHT6WJANCNFSM6AAAAAAQJ4LUFM . You are receiving this because you authored the thread.Message ID: @.***>

KM8Oz avatar May 23 '23 18:05 KM8Oz