Add negation support to JsonPathMatcher filter expressions#7164
Merged
steve-aom-elliott merged 1 commit intomainfrom Mar 27, 2026
Merged
Add negation support to JsonPathMatcher filter expressions#7164steve-aom-elliott merged 1 commit intomainfrom
steve-aom-elliott merged 1 commit intomainfrom
Conversation
The `!` (NOT) operator was previously stubbed out in the ANTLR grammar. This enables negation in filter expressions across the JSON, YAML, and HCL modules, supporting syntax like `[?(!@.property)]` for negating existence checks and `[?(!(@.key == 'value'))]` for negating equality, regex, and contains expressions. Negation also composes with `&&`/`||` logical operators.
7c4085f to
965ea48
Compare
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.
Summary
NOT(!) token in the ANTLR JsonPath grammar and adds anegationExpressionparser rule supporting[?(!@.prop)]and[?(!(@.key == 'val'))]syntaxvisitNegationExpressionin theJsonPathMatchervisitor for all three modules (rewrite-json, rewrite-yaml, rewrite-hcl), handling both list/array iteration (collecting non-matching elements) and single-scope boolean flip&&/||logical expressions so filters like[?(!@.x && @.y == 'z')]workTest plan
./gradlew :rewrite-json:test --tests "org.openrewrite.json.JsonPathMatcherTest"— all pass./gradlew :rewrite-yaml:test --tests "org.openrewrite.yaml.JsonPathMatcherTest"— all pass./gradlew :rewrite-hcl:test --tests "org.openrewrite.hcl.JsonPathMatcherTest"— all pass