alibaba / alibaba/fastjson2

[BUG] JSONPath解析嵌套数组的结果不正确

Open
#4,007 0 comments 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

### 问题描述
使用jsonpath解析json,返回结果与期望不一致

### 环境信息
*请填写以下信息:*

- OS信息: [macOS:14.8.1 (23J30) 内存:16 GB 2667 MHz DDR4 处理器:2.6 GHz 六核Intel Core i7]
- JDK信息: [openJDK 17.0.2]
- 版本信息:[Fastjson2 2.0.60]

### 重现步骤
*如何操作可以重现该问题:*

1. 使用 方法 :
本地新建main方法
2. 输入数据
```json
{
"activityId": "9260304192237310917"
"activityRuleDtos": [
{
"awardId": "8260304192237381811"
"promotionRuleDtos": [
{
"field": "dataCenterUserTagLimit"
},
{
"field": "tradeTime"
},
{
"field": "skuLimit"
}
]
},
{
"awardId": "8260304192237401811",
"promotionRuleDtos": [
{

"field": "tradeTime"
},
{
"field": "skuLimit"
}
]
}
]
}
```
3. java代码
```java
String jsonPathConfig1 = "$.activityRuleDtos[?(@.promotionRuleDtos[?(@.field == 'dataCenterUserTagLimit')])].awardId";
Object value1 = JSONPath.extract(json, jsonPathConfig1);
System.out.println(value1);
```

### 期待的正确结果
期待输出:["8260304192237381811"]

### 相关日志输出
控制台输出:["8260304192237381811","8260304192237401811"]

#### 附加信息

Contributor guide

Open the contributing guide

Research direction

Start with JSONPath.extract and reproduce the nested-array predicate using the JSON and path shown in the issue. Trace why the filter matches both activityRuleDtos entries, then verify that the result contains only "8260304192237381811" without changing unrelated JSONPath behavior.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.