Ability to remove JSON fields using JSONPath #106
Merged
besok merged 3 commits intobesok:mainfrom Jul 30, 2025
Merged
Conversation
Owner
|
First of all, thank you for the PR. I think it is gonna be usefull so let's try to merge it in. |
besok
reviewed
Jul 28, 2025
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()); |
Owner
There was a problem hiding this comment.
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>; |
Owner
There was a problem hiding this comment.
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,
Owner
|
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
besok
approved these changes
Jul 30, 2025
Owner
|
thank you for the pr |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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