-
Notifications
You must be signed in to change notification settings - Fork 32
Ability to remove JSON fields using JSONPath #106
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
Conversation
First of all, thank you for the PR. I think it is gonna be usefull so let's try to merge it in. |
src/query/queryable.rs
Outdated
// Sort deletions to handle array indices correctly (delete from end to start) | ||
deletions.sort_by(|a, b| { | ||
// First sort by path depth (deeper paths first) | ||
let depth_cmp = b.path_depth().cmp(&a.path_depth()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
can be done in one seq
deletions.sort_by(|a, b|
b.path_depth().cmp(&a.path_depth()).then_with(|| {
match (a, b) {
(
ArrayIndex { index: idx_a, .. },
ArrayIndex { index: idx_b, .. },
) => idx_b.cmp(idx_a),
_ => std::cmp::Ordering::Equal,
}
})
);
src/query/queryable.rs
Outdated
|
||
/// Deletes a single element at the given path | ||
/// Returns true if an element was deleted, false otherwise | ||
fn delete_single(&mut self, path: &str) -> Result<bool, JsonPathError>; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What do you think would be the cases when this method is needed?
For now it throws exception if it does not get slice or index,
added a couple of stylistic thinks to discuss |
- Move delete_by_path from separate trait to Queryable trait - Use Queried<usize> type alias instead of Result for consistency - Remove delete_single method in favor of unified delete_by_path - Simplify error handling by preserving original query errors
thank you for the pr |
This PR adds deletion capabilities to the jsonpath-rust crate by implementing delete_by_path() and delete_single() methods in the Queryable trait. #105
New Methods
Usage Examples