Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTION] JSONPath 支持这种需求吗? #2190

Closed
qichhhhh opened this issue Jan 15, 2024 · 4 comments
Closed

[QUESTION] JSONPath 支持这种需求吗? #2190

qichhhhh opened this issue Jan 15, 2024 · 4 comments
Labels
enhancement New feature or request fixed question Further information is requested
Milestone

Comments

@qichhhhh
Copy link

{"code":0,"errMsg":"","Data":{"is_focus":1,"user_info":{"userid":"13814","nickname":"没事改昵称"}}}

JSONPath 能做到判断 Data.user_info.userid 这个 key 如果存在的话返回 Data 的 value 吗 ?
应该怎么写呢,感谢各位

@qichhhhh qichhhhh added the question Further information is requested label Jan 15, 2024
@wenshao wenshao added the enhancement New feature or request label Jan 15, 2024
@wenshao wenshao added this to the 2.0.46 milestone Jan 15, 2024
@wenshao
Copy link
Member

wenshao commented Jan 15, 2024

现在不支持,将会2.0.46版本(春节前发布)支持

@wenshao
Copy link
Member

wenshao commented Jan 17, 2024

    public void test() {
        String str = "{\"code\":0,\"errMsg\":\"\",\"Data\":{\"is_focus\":1,\"user_info\":{\"userid\":\"13814\",\"nickname\":\"没事改昵称\"}}}";
        JSONObject jsonObject = JSON.parseObject(str);
        assertSame(jsonObject, JSONPath.eval(jsonObject, "[?exists(@.Data.user_info.userid)]"));
        assertNull(JSONPath.eval(jsonObject, "[?exists(@.Data.user_info.userid1)]"));
        assertNull(JSONPath.eval(jsonObject, "[?exists(@.Data.user_info1.userid)]"));
        assertNull(JSONPath.eval(jsonObject, "[?exists(@.Data1.user_info.userid)]"));
    }

https://oss.sonatype.org/content/repositories/snapshots/com/alibaba/fastjson2/fastjson2/2.0.46-SNAPSHOT/
已经支持,请帮忙用2.0.46-SNAPSHOT版本验证,正式版本预计在3月初发布。

@wenshao wenshao added the fixed label Jan 19, 2024
@qichhhhh
Copy link
Author

可以正常匹配并且返回 Data 的 value 了,感谢 @wenshao

@wenshao
Copy link
Member

wenshao commented Jan 29, 2024

@wenshao wenshao closed this as completed Jan 29, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request fixed question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants