1
votes

I'm trying to extract the parameter roomNo from the following JSON with JMETER XPATH Extractor:

*/
{   
"categoryCode": ["I4"],
"Response": {
    "class": "example",
    "availables": {
        "available": [
            {
                "Desc": " Middle",
                "roomNo": "5049"
            },
            {
                "Desc": " Middle",
                "roomNo": "5062"
            }
            ],
        "class": "test"
    },
    "advisoryInfo": null
},
"storeId": "10251"
}
*/

i use the following expression with no success:

/Response/availables/available[0]/roomNo

is the expression wrong?


UPDATE:

i'm try to use the plugins JSON PATH EXTRATCTOR. i tryied the following queries with no success:

$...available[0]

$.Response.availables.available..roomNo[0]

$.Response.availables.available[0].roomNo

UPDATE1:

one more consideration: the ajax response I recieve starts with */, is it possible this creates troubles with JSON EXTRACTOR? i see the response through view Results Tree


UPDATE2: i try the following approach:

ajax request followed by bash extractor, followed by json extractor but it is still not working

in bash extractor i did as suggested using the following strings String temp = new String(prev.getResponseDataAsString()); prev.setResponseData(temp.replaceAll("\*/","").getBytes());

some more question:

is it possible to see the result of bash extractor? should i declare before json extractor that it should use temp variable? how?

1
Thanks for UPDATE1, didn't realize that it's a part of response. JSONPath Extractor won't consume it, you'll need to remove them somehow.Dmitri T
It's possible to see variables values using Debug Sampler - jmeter.apache.org/usermanual/… I see replaceAll("\*/",""), please double check it. It should be escaped by additional slash as replaceAll("\\*/","") as replaceAll assumes regexDmitri T
I finally used regex extractoruser3299274

1 Answers

0
votes

I'm afraid XPath Extractor won't let you parsing JSON.

You'll need JSONPath Extractor available via JMeter Plugins (you need Extras with Libs Set).

In your case relevant JSONPath query will look like:

$.Response.availables.available..roomNo[0]

Check out Using the XPath Extractor in JMeter guide (scroll down to Parsing JSON) for more information and XPath to JSONPath mappings table.

Hope this helps.

UPD. You can use Beanshell Post Processor to get rid of your */ bits, in that case JSONPath should work fine. Beanshell PostProcessor code:

String temp = new String(prev.getResponseDataAsString());
prev.setResponseData(temp.replaceAll("\\*/","").getBytes());

Make sure that Beanshell Post Processor goes before JSONPath Extractor.