Skip to content

continue to deal the result as a array after filter #202

Description

@NingGelin

Motivation

I have a json like this:

{
"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"
},
}
]
}

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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions