-
Notifications
You must be signed in to change notification settings - Fork 20
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
Singular path as selector #522
Comments
But it can be expressed with the filter with test-expr. |
@He-Pin Can you please help with the expression. I tried multiple ways drawing inspiration from here #156 but could not come up with a working one, because none of the method could give me the value of inner path |
I like this syntax. Equivalent results could be achieved using a filter selector and a non-standard key/index identifier or function. I've tried to describe such a current key identifier here (
But a singular path being coerced to a name or index selector looks nicer to me. |
@vishalJ16 I think the root cause is current filter selector only works on the member's value, I would like to have a key filter, something like the Updated:
Another thing we need to address is , how to pass the |
With jayway, it's possibly, you need to register a pathfunction with reflection. |
@He-Pin I've been treating the result of
An alternative might be to allow function extensions to accept a union of types for a parameter. Then, for example, |
Here's my attempt at describing a singular query selector. I'm still undecided as to whether the root identifier should be explicit or implicit for embedded queries. If the embedded query starts with a bracketed selection, the
vs
Singular Query SelectorThe singular query selector consist of an embedded absolute singular query, the result of which is used as an object member name or array element index. If the embedded query resolves to a string or int value, at most one object member value or array element value is selected. Otherwise the singular query selector selects nothing. Syntax
Examples{
"a": {
"j": [1, 2, 3],
"p": {
"q": [4, 5, 6]
}
},
"b": ["j", "p", "q"],
"c d": {
"x": {
"y": 1
}
}
}
|
Sorry I am a bit confused. To register my custom function to jsonpath, I would required these code changes json-path/JsonPath#286 mentioned here json-path/JsonPath#246, or can it be done without them? These changes still not merged. |
You can change it with Java Reflection or MrthodHandles。 |
FWIW, in my implementation I allow custom functions to be provided to the parser, with some available almost out-of-the-box: {
"name": "key(), palindromic keys",
"selector" : "$[?key(@) == reverse(key(@))]",
"document" : {"foo": "FOO", "bar": "BAR", "bab": "BAB", "": "", "a": "A"},
"result": ["BAB","","A"]
}, |
@f3ath, that doesn't pertain to this issue. This issue is about creating a new selector that is itself a path, not custom functions. |
@jg-rp, we have another issue for grabbing the key in an expression. Arguably, that allows for more functionality, but unfortunately it hasn't been received well. |
@jg-rp you bring up a good point about including the root selector. I think it should be required. I wonder if the relative root makes sense to also define.
Recursively select the value in objects indicated by the object's Of course this entire feature can also only be defined for keys which are strings (names) or numbers (indices). It wouldn't select anything if the value ends up being any other JSON value type. |
Inspired by a StackOverflow question, I think a singular path could be a viable selector.
The example given is
I see this as taking the value in
productData.products[0].addressRefId
as the selector value.This would, for example, allow the data to contain the index of an array (or the key of an object) to select, amongst other similar functionality.
If we could work out a way to support multi-value paths, that'd be cool, but I think singular paths are simple enough to do.
The text was updated successfully, but these errors were encountered: