Replies: 6 comments 7 replies
-
Is jsonpath filtering on a struct (as opposed to map) supported?
|
Beta Was this translation helpful? Give feedback.
-
Reformtted a bit but the same code with one exception. An instead of // filter with map
{
path: "$.x[?(@.b=='sample1')].a",
expect: []interface{}{3},
data: map[string]interface{}{"x": []interface{}{map[string]interface{}{"a": 3, "b": "sample1"}}},
},
{
path: "$.x[?(@.a==3)].b",
expect: []interface{}{"sample1"},
data: map[string]interface{}{"x": []interface{}{map[string]interface{}{"a": 3, "b": "sample1"}}},
},
// filter with struct
{
path: "$.x[?(@.b=='sample2')].a",
expect: []interface{}{3},
data: Any{X: []interface{}{&Sample{A: 3, B: "sample2"}}},
},
{
path: "$.x[?(@.a==4)].b",
expect: []interface{}{"sample2"},
data: Any{X: []interface{}{&Sample{A: 4, B: "sample2"}}},
}, |
Beta Was this translation helpful? Give feedback.
-
Thanks for the praise. Feedback and use in various ways it the best way for me to make it better. |
Beta Was this translation helpful? Give feedback.
-
Give branch bug/jsonpath-reflect-arrays a try. |
Beta Was this translation helpful? Give feedback.
-
Is it possible to get the index after filter? For example, "$.x[?(@.b=='sample2')].index" where "index" is an implicit field for the array index. If it is not supported, do you think it is a good idea to add such syntax? Thank you. |
Beta Was this translation helpful? Give feedback.
-
Hi, I just noticed that a json path with open intervals and negativ steps mostly produces rather unintuitive results. |
Beta Was this translation helpful? Give feedback.
-
JSON Path is super useful for navigating not only JSON but data held in memory. Let's keep discussions of JSON Path here starting with this comparison of many implementations across a variety of languages.
Beta Was this translation helpful? Give feedback.
All reactions