14

Hi I want get legth of array after Filter with JsonPath.

Is it possible ?

My filter is $.issues.[?(@.severity == 'MAJOR')].length()

My Json is

{
  "issues": [
        {
            "severity": "MAJOR"
        },
                {
            "severity": "MINOR"
        },
                {
            "severity": "MAJOR"
        },
                {
            "severity": "MAJOR"
        },
                {
            "severity": "MAJOR"
        }
]
  
}

6
  • Can you please tag your question with the language you are working in? See stackoverflow.com/help/tagging. In the original JSONPath proposal goessner.net/articles/JsonPath a query returns (array|false) : Array holding either values or normalized path expressions matching the input path expression, which can be used for lazy evaluation. false in case of no match. So there is nothing that returns the count of matches in the proposal itself. But maybe your language & framework supports something. Or you can just count the number of items returned afterwards. Commented Apr 23, 2018 at 13:58
  • What about Jayway JsonPath implementation: the following JsonPath expression seems to be valid yet it returns incorrect result: see sample Commented Jun 6, 2018 at 12:50
  • @begie that example returns the count of keys of the map (category, author, title, price). Commented Apr 24, 2019 at 14:02
  • It's been some time but I believe that's why my comment says incorrect result is returned... Commented Apr 26, 2019 at 7:03
  • Any update on this? I think length is just for basic approaches Commented Jan 22, 2021 at 15:35

1 Answer 1

8

Possible workaround for Jayway JsonPath implementation

$.length($.issues.[?(@.severity == 'MAJOR')].length())
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.