You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I wanted to ask if it's possible to do something following with this crate.
I want to be able to run multiple queries on some JSON to eventually find a node that I'd like to modify/remove.
In the following example, I'm trying to remove the genre of the second book from the list.
use std::str::FromStr;
use serde_json::{Value};
use jsonpath_rust::{JsonPathFinder, JsonPathInst, JsonPathQuery};
fn main() {
let data = r#"
{
"books": [
{
"title": "Title 1",
"details": {
"description": "Description 1",
"genre": "Genre 1"
}
},
{
"title": "Title 2",
"details": {
"description": "Description 2",
"genre": "Genre 2"
}
}
]
}
"#;
let json: Value = serde_json::from_str(data).unwrap();
let books_path = JsonPathInst::from_str("$.books").unwrap();
let finder = JsonPathFinder::new(Box::from(json), Box::new(books_path)); // had to clone due to ownership
let books = finder.find_slice().get(0).unwrap().clone().to_data();
let second_book = books.get(1).unwrap();
let genre_value = second_book.clone().path("$.details.genre").unwrap(); // had to clone due to ownership in path
// remove genre_value
}
Do you have any suggestion how to achieve this?
If I'm not mistaken find returns new Values and find_slice return reference to the Value. However none of them return mutable reference, maybe adding it could help with this?
Or maybe once the feature mentioned in #31 is added I could find the paths that are to be removed/modified, clone whole "original" json and modify it using these paths 🤔
If you have any other idea please point me to the right direction 🙏
Thanks!
The text was updated successfully, but these errors were encountered:
Hello 👋
I wanted to ask if it's possible to do something following with this crate.
I want to be able to run multiple queries on some JSON to eventually find a node that I'd like to modify/remove.
In the following example, I'm trying to remove the genre of the second book from the list.
Do you have any suggestion how to achieve this?
If I'm not mistaken
find
returns new Values andfind_slice
return reference to the Value. However none of them return mutable reference, maybe adding it could help with this?Or maybe once the feature mentioned in #31 is added I could find the paths that are to be removed/modified, clone whole "original" json and modify it using these paths 🤔
If you have any other idea please point me to the right direction 🙏
Thanks!
The text was updated successfully, but these errors were encountered: