alibaba / alibaba/fastjson2

[BUG] fastjson2中jsonpath表达式嵌套执行报错

Open
#2,150 1 comment 0 reactions 0 assignees View on GitHub
bug
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

fastjson版本:2.0.43,场景:检索某个路径下的某个字段,在另外一个jsonpath的取值范围
表达式:$.person[?(@.city in $.city)]
demo:
String testJson = "{\"city\":[\"shanxi\",\"heilongjiang\"],\"person\":[{\"name\":\"dongxp\",\"city\":\"shanxi\"},{\"name\":\"dongxp\",\"city\":\"heilongjiang\"}]}";
JSONObject json1 = JSONObject.parseObject(testJson);
Object results1 = JSONPath.eval(json1, "$.person[?(@.city in $.city)]");
执行结果:
![image](https://github.com/alibaba/fastjson2/assets/18159554/609cd1eb-df41-427a-965e-b38f94d6ab4d)
期望:同jayway的jsonpath一样,可以正常执行获取结果
![image](https://github.com/alibaba/fastjson2/assets/18159554/a6e3f760-ad4e-47b6-ae0a-7890cf989d1c)

Contributor guide

Open the contributing guide

Research direction

Start at the JSONPath.eval entry point and reproduce the issue with the supplied JSON and expression $.person[?(@.city in $.city)]. Trace the nested JSONPath lookup and add or update a focused test if the project has one; done means the expression returns both matching person objects, as in the Jayway JSONPath result.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.