I have a json response as, { 'sadasd123242' : 'asdadada122dfsfs', 'dadsadaskljk' : 'adasdasdasdsadds' } I want to extract the keys from the response in jmeter test using the JSON extractor. I am unable to do this as I do not know the keys in the response. How do I get the keys ?
Asked
Active
Viewed 1,418 times
2 Answers
2
Assuming you have the response in the following format:
{
"data": {
"assets": {
"sadsad12dwqqwe": "asda1212312",
"asdasd1213123": "asdas2131231"
}
}
}
You can extract key names using JSR223 PostProcessor and the following code:
new groovy.json.JsonSlurper().parse(prev.getResponseData()).data.assets.eachWithIndex{ def node, int idx ->
log.info('Key ' + idx + '=' + node.getKey())
vars.put('key_' + idx, node.getKey())
}
It will print key names into jmeter.log file and create JMeter Variables like:
- `${key_1}`
- `${key_2}`
- etc.
holding the required "key" values.
Demo:
References:

Dmitri T
- 159,985
- 5
- 83
- 133
0
Considering first value as key which is dynamic and second value you have to fetch.
You can use "Boundary extractor" post processor in that case by defining the left and right boundary as shown in the below image.
Check the below test for boundary expression to get the desired result:-
Hope this help.

sunny_teo
- 1,961
- 1
- 7
- 11
-
My response format is {data:{"assets":{'sadsad12dwqqwe':'asda1212312','asdasd1213123':'asdas2131231''}}} How do I user boundary extractor for this ? – rutuja yewalekar May 01 '18 at 06:30
-
I have used the same example code to fetch values. Check the snapshot, I have used the boundaries and also shown the result. – sunny_teo May 01 '18 at 19:01