Forum Discussion

smaloney's avatar
smaloney
Occasional Contributor
2 years ago
Solved

JSONPath Count not picking up nodes under item

Hello,

I'm having a hard time getting ReadyAPI to count the nodes properly under a parent node.

See screenshot.  This should return a count of "3" but only returns a count of "1".

I've tried adding assert by right clicking on the item as well as browsing out to the item, but I still only get a count of "1".

Does anyone else know what might be going on?  Is this a bug in ReadyAPI?  Our whole team is experiencing this problem.

 

 

 

 

5 Replies

    • smaloney's avatar
      smaloney
      Occasional Contributor

      Hello,

      Thanks for responding.  Let me see what I can do to get you the data.

       

    • smaloney's avatar
      smaloney
      Occasional Contributor

      I'd rather not post data on an open forum.  Do you have a direct email I can send it to?

       

    • smaloney's avatar
      smaloney
      Occasional Contributor

      I'd rather not post data on an open forum.  Do you have a direct email I can send it to?

       

  • KarelHusa's avatar
    KarelHusa
    Champion Level 3

    smaloney,

    ReadyAPI evaluates your JSONPath expression correctly. You can check other JSONPath tools, e.g., https://jsonpath.com/ , and you will get the same result.

     

    In your JSON, you have a single JSON object fieldToStateFunctions. So, if you ask how many fieldToStateFunctions objects are, you get 1.

     

    Inside your fieldToStateFunctions, you have the following properties with names:

    VALS-GROUP:VAL1

    VALS-GROUP:VAL2

    VALS-GROUP:VAL3

     

    These are distinct properties with different names, so you cannot easily count them too.

     

    If you have any property which occurs only once inside the VALS-GROUP:VAL, you can use it in your query, e.g., signature:

    $.fieldToStateFunctions..signature

    Such JSONPath will give you three if you count the result nodes. But if more signatures occur within the element, the test would fail, so check if it is the right element. 

     

    Anyway, the JSON is pretty tough to understand. If you simplify the API, it would be easier to use and easier to test as well.

     

    Best regards,

    Karel