-
-
Notifications
You must be signed in to change notification settings - Fork 180
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
continue to deal the result as a array after filter #202
Comments
+1 to this issue. I think I can get my company to sponsor the fix (depending on the cost). |
The length attribute works by happy accident today. This adds initial explicit support for it and also gets it work with filter conditions. This is not complete support. It won't (for instance) work correctly within array filter conditions. See the test changes for use cases it does add support for. Note that the ietf standardization for length() and count() functions is done differently. See: https://ietf-wg-jsonpath.github.io/draft-ietf-jsonpath-base/draft-ietf-jsonpath-base.html#name-length-function-extension Fixes JSONPath-Plus#202
@NingGelin I am not able to understand the use-case. Why can't we use something like const data = {
"contactMedium": [
{
"@type": "EmailContactMedium",
"preferred": true,
"contactType": "other",
"validFor": {
"startDateTime": "2018-10-22T08:31:52.028Z"
},
"emailAddress": "tom@email.com"
},
{
"@type": "GeographicAddressContactMedium",
"preferred": true,
"contactType": "other",
"validFor": {
"startDateTime": "2018-10-22T08:31:52.028Z"
},
}
]
}
const result = JSONPath({ path: '$.contactMedium[?(@.preferred==true)]', json: data }).length |
I think the use case would be for applications which exposed JSONPath expressions to users, and to allow the users to make a query which performed a count. We should probably not be making custom additions to the JSONPath standard now though, so I would discuss any new proposals (e.g., for a count function) with the standards-making body if there is not already one in effect. |
Motivation
I have a json like this:
I want to get the number of item with preferred==true
const result = JSONPath({ path: '$.contactMedium[?(@.preferred==true)].length', json: data })
Current behavior
got []
Desired behavior
got 2
Alternatives considered
currently, i can got the result expected by this way.
const result = JSONPath({ path: '$.contactMedium[?(@.preferred==true)]', json: data })
console.log(result)
const result2 = JSONPath({ path: '$.length', json: result })
console.log(result2)
The text was updated successfully, but these errors were encountered: