0

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?

el n00b
  • 1,957
  • 7
  • 37
  • 64
  • NeoLoad as a library (and Java as a language) has its own defined rules - it is not a valid assumption to equate these with "online path evaluator I found" or "some other library" without further evidence. Honor NeoLoad (and Java) in their own right, utilizing the respective documentation. There is currently no shown code that "returns an error". It is important, because in such questions *it is often that [unshown user] code that is wrong in context*; even if this code *is* "valid" in a large context, such can't even be argued for because it's *not shown*. – user2864740 Feb 21 '18 at 18:34
  • That's why I mentioned I updated my path expression to follow the documentation from Jayway JSON Path library for Java. – el n00b Feb 21 '18 at 18:39
  • And still no code/context .. the beliefs in what is used or how something "should work" are *simply beliefs*. They can be turned into *hypothesis* and tested. Repeat the cycle until there is agreement. The *documentation* (and even scouring implementation) can provide insight. – user2864740 Feb 21 '18 at 18:39

1 Answers1

2

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

shrikul
  • 73
  • 6