Skip to content

Fix JSONPath syntax error with in filter after other filters#4001

Open
caglareker wants to merge 2 commits intoalibaba:mainfrom
caglareker:fix/issue-3997-bug-jsonpath-syntax-error-when-other-fil
Open

Fix JSONPath syntax error with in filter after other filters#4001
caglareker wants to merge 2 commits intoalibaba:mainfrom
caglareker:fix/issue-3997-bug-jsonpath-syntax-error-when-other-fil

Conversation

@caglareker
Copy link

Summary

Fix a parser error that occurred when using an 'in' filter in combination with other filters in JSONPath expressions. The parser was unconditionally requiring a closing parenthesis after parsing filters, which caused syntax errors when the 'in' filter's own parentheses were present.

Changes

Modify the filter parsing logic in JSONPathParser to only enforce the closing parenthesis requirement when the filter expression itself is wrapped in parentheses. This allows 'in' filters with their own parenthetical syntax to work correctly after other filter conditions.

Testing

Add test cases validating:

  1. An 'in' filter used after other filter conditions (e.g., @.field=='value' && @.type in ('01','04'))
  2. An 'in' filter used before other filter conditions

Both scenarios now parse and evaluate correctly.

Fixes #3997

When parsing filter expressions, the parser was unconditionally requiring
a closing parenthesis even when the filter wasn't wrapped in parentheses.
This caused errors when an 'in' filter followed other filter conditions,
since the 'in' filter has its own parenthetical syntax.

Only enforce the closing parenthesis requirement when the filter itself is
wrapped in parentheses.
@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.


import static org.junit.jupiter.api.Assertions.assertEquals;

public class JSONPath_in_filter_issue3997 {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you please move this unit test to the test/java/com/alibaba/fastjson2/issues_3900 directory and rename the class to Issue3997? Thanks

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done, moved it

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK. Let's wait for @wenshao to review this, as he handles all write operations.

@wenshao
Copy link
Member

wenshao commented Mar 10, 2026

This PR fails the unit test; please try merging from the main branch.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG] jsonpath syntax error when other filters are followed by 'in' filter

4 participants