Search code examples
jsonjsonpathneoload

JSON Path - size of root array element (NeoLoad)


I'm using NeoLoad 6.3.1 at the moment and am trying to get the length of an array where the array itself is the root element.

Given the following sample JSON:

[
  { "id": 1, "title": "Item 1" },
  { "id": 2, "title": "Item 2" },
  { "id": 3, "title": "Item 3" },
  { "id": 4, "title": "Item 4" },
  { "id": 5, "title": "Item 5" }
]

I want to just get back the answer of "5".

If I use the JSON Path Online Evaluator, I can use $.length and it returns:

[ 5 ]

In NeoLoad 6.3.1, that returns an error.

As NeoLoad is Java-based, I am assuming that they're using the com.jayway.jsonpath's json-path library (or something similar). Based on the documentation there I updated the query to be $.length() but did not have any luck.

Any suggestions?


Solution

  • In Neoload, there is "Variable Extractor" action where you can provide left boundary, right boundary for any one of the subnode in your array. e.g. LB:"title": " RB: " } and select "extract call occurrences" option. This variables can be accessed via "variablename_matchNr" which gives count of all occurrences of given extraction. Better explained here: http://answers.neotys.com/questions/590268-created-variable-extractor-last-occurrence-extracted-values

    Neload also provides JSON path expression in variable extractor where user can select any one node and select "extract call occurrences". Neoload variable extractor