0

I’m working with an application that handles the submission and processing of filings, and I’m trying to perform a load test where different users target different filings and perform different actions depending on the filings’ status. This information exists within an incredibly long JSON response that is sent from the server, which also contains all the information on all the filings. It is particularly convenient, however, that the fields I’m interested in are close enough to each other to try to correlate them.

The way I’m going about this is the following: I need to extract each filing’s ID number in order to target it, and I need to be able to randomly target filing IDs that are associated with a specific status. The structure of the response that I care about is as follows:

{
    "responseObject":{
        "baseFilingRequests":{
            "^Value":[
            {"fields":"[values]"},
            {"fields":"[values]"},
            {
                "fields":"values",
                "referencedListings":"[value]",
                "id":"[value]",
                "referenceId":"[value]",
                "status":"[value]",
                "filingName":"[value]",
                "fields":"values",
            },
            {"fields":"[values]"},
            {"fields":"[values]"}
            ]
        }   
    }
}

So I figured I could just stick this expression in the RegEx and modify the status field for each thread group so each would target filings with a different status (STATUS_APPROVED, STATUS_REJECTED, and so on), and then just extract the ID of each filing it finds, using an expression like this:

\"referencedListings\":null,\"id\":\"(.+?)\",\"referenceId\":\"\d\d\d\d\d\d\d\”,\"status\":\"STATUS[_]RECEIVED\",

However, the underscore is giving me trouble when trying to extract IDs of filings with the status I specify. Sometimes it captures a different status (capturing a filing ID that corresponds to a filing with a STATUS_CANCELLED status, instead of the STATUS_LOCKED that I specify), sometimes it captures an ID but it doesn't stop extracting there; it extracts as much of the response that comes after it as it can, inserts this massive string in the variable, and then attempts to use that as a filing ID in my later requests, generating null pointer exceptions. This behavior is erratic and seemingly random, and I am at a loss as to how to solve this.

I’ve tried escaping the character using backslashes, and just about every other syntax I’ve been able to think of, but this behavior persists. It is the underscore without a doubt because whenever I try the expression using only everything that comes before the underscore, the RegEx behaves consistently and predictably. But I can’t just omit it, because it’s part of the syntax of the status that I need to detect so I can filter filings accordingly, more so when statuses like STATUS_PENDING_UNLOCK contain two underscores and I need to be able to detect both.

Any insight on this matter would be greatly appreciated.

Don
  • 1
  • 1
  • Can you please use JSON Extractor? Syntax is `$..id` which will retrieve all the instances of `id`. You can use that in the subsequent requests. myvar_1, myvar_2 etc. `The JSON PostProcessor enables you extract data from JSON responses using JSON-PATH syntax. This post processor is very similar to Regular expression extractor. It must be placed as a child of HTTP Sampler or any other sampler that has responses. It will allow you to extract in a very easy way text content, see JSON Path syntax .` For more details, check http://jmeter.apache.org/usermanual/component_reference.html#JSON_Extractor – NaveenKumar Namachivayam May 03 '17 at 16:50
  • This sounds very useful. However, if there are other fields called id within the response where all the filings are contained, that do not specifically correspond with the filing IDs I'm aiming to extract, would this work by itself? More importantly, what kinds of conditions would I have to set so that it extracts only the id fields that also exist alongside a status fields with the specific status values I'm looking for? – Don May 03 '17 at 17:06
  • The `id` will be retrieved based on your syntax which you mention in the `JSON Extractor`. E.g. `$..id` will retrieve only ALL the `id` in the JSON structure. If the `id` located somewhere in the JSON structure, it will not extract. Please post the complete JSON, I will be able to provide you the exact syntax. Thanks! – NaveenKumar Namachivayam May 03 '17 at 17:10
  • Alright thanks, I updated the original post with a more visible code structure. Within each nested level there are many other fields, but I only included the ones I care about. Within the Value field there are hundreds of groupings, and only some of then contain filing IDs and statuses, and it is these that I need to be able to filter and select randomly from. I appreciate all your help! – Don May 03 '17 at 20:26
  • You JSON is not valid. Can you please post the right one? – NaveenKumar Namachivayam May 03 '17 at 21:11
  • I added more elements to illustrate the structure better. If something is unnecessary here let me know, I hope this helps. – Don May 03 '17 at 21:31
  • Can you please use this config in JSON Extractor? http://imgur.com/a/NhOUt `JSON Path Expression` is `$.responseObject.baseFilingRequests.Value..id`. I hope you will be able to catch the IDs. – NaveenKumar Namachivayam May 04 '17 at 00:20
  • The above JSON you shared throwing error. I fixed it. Here is the valid JSON. `{ "responseObject": { "baseFilingRequests": { "Value": [{ "fields": "[values]" }, { "fields": "[values]" }, { "fields": "values", "referencedListings": "[value]", "id": "[value]", "referenceId": "[value]", "status": "[value]", "filingName": "[value]" }, { "fields": "[values]" }, { "fields": "[values]" } ] } } }` – NaveenKumar Namachivayam May 04 '17 at 00:20

1 Answers1

0

Simply don't use regular expressions to perform correlation on JSON data (same applies to XML and HTML)

Starting from JMeter version 3.0 there is JSON Extractor which you can use to perform correlation using JSON Path language

Community
  • 1
  • 1
Dmitri T
  • 159,985
  • 5
  • 83
  • 133