0
votes

We are receiving a JSON response from a web service - which we can easily parse using JMeter when running tests. The problem that we recently found is that the fields in the JSON object are not always in the same order. Therefore, regex will break.

Here are the solutions we have tried:

1.) JSON path extractor (from jp@gc):
This is pretty cool and lets you choose the element that you want. The problem is that when there is a null value, it won't read it at all.

2.) Then we tried adding a BeanShell -pre-processor to set the variable to null initially, so that when it reaches the conditional it is executed properly. The problem with this approach is that once set to null, it won't change to anything if a value is picked by the JSON path extractor.

Does anyone have any ideas on other ways I could get this to work? Let me know if you have any questions or need clarification.

1

1 Answers

0
votes

Here is how I have done in one of you test case as an alternative.

- HTTP Sampler
 - BSF Post processor with javascript language
    - script in BSF goes like this
      - log.info("processing image index response");
if ("" != prev.getResponseDataAsString()) { //if response is not empty process it
    eval( 'var indexJSON = ' + prev.getResponseDataAsString() ); //get the respnose JSON string as javascript var and operate on it as you like
    vars.putObject("indexJSON", indexJSON);

    var next_slide_timestamp=indexJSON[0].timestamp;
    vars.put("next_slide_timestamp", "0");

    var maxSlides=indexJSON.length;
    vars.put("maxSlides", maxSlides);
} else { //if response is empty simply initialize all var to 0
    vars.put("currentThumb", "0");
    vars.put("currentSlide", "0");
    vars.put("next_slide_timestamp", "0");
    vars.put("maxSlides", "0");
                          log.info("index time : empty response , setting defaults to zero");
}