alibaba / alibaba/fastjson2

jsonpath能否支持[*]相关的解析

Open
#1,327 3 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Java
Stars
4.4k
Forks
613
Avg merge
1d 22h
Merged PRs (30d)
6

Description

### 请描述您的需求或者改进建议
*对您想要需求或建议的清晰简洁的描述。*
$.data.allFilters[*].details[*].detailItems[*].labels
1.支持类似这种多层嵌套[*]的jsonpath解析
2.set操作能否支持批量替换,类似:JSONPath.eval(object,"$.data.allFilters[*].details[*].detailItems[*].labels", arrayList);

### 请描述你建议的实现方案
*对您想要需求或建议的实现方案的详细描述。*
在JSONPathSegmentName中增加了对QunarJSONPath.Sequence的识别,基本可以实现批量替换的功能,但是存在一些细节性的bug,可以逐个修复,比如执行set时本意是希望替换,结果set执行添加的操作,导致结果错乱

### 描述您考虑过的替代方案
*对您考虑过的任何替代解决方案或功能的描述。*
尝试过使用paths = JSONPath.paths(jsonObject);的方法将含*的path替换成具体index的path,在逐个set,能够实现我的功能,但进行性能对比发现耗时是批量耗时的两倍多

#### 附加信息
*如果你还有其他需要提供的信息,可以在这里填写(可以提供截图、视频等)。*
![image](https://user-images.githubusercontent.com/43124474/230316881-464fede6-367b-486e-b095-7471ca0261dc.png)

Contributor guide

Open the contributing guide

Research direction

Start with JSONPathSegmentName and the JSONPath.eval call shown in the issue, then compare the proposed nested [*] path with the existing JSONPath.paths approach. Check how set handles $.data.allFilters[*].details[*].detailItems[*].labels; done means nested wildcards parse correctly and batch set replaces matching values without adding or scrambling results.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
backend
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.