How to get value from the json response where a key is dynamic in Jmeter

51 views Asked by At

I want to extract a token from the the given below JSON response where the key of the token is dynamic. The key 57 is dynamic. it change every time. I know that how to extract value by given key but in my case the Key is dynamic. And based on the founded key I want to extract value.

On bottom of the question a complete JSON can be found, which is very shortened to better describe my problem.

{
  "message": "Too many sessions, log out please, on one of your devices",
  "active": {
    "57": [
      "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjY5ODAiLCJlbWFpbCI6IkBAc3ViamVjdCsxQG9zYXQuY29tK29zYXQiLCJmaXJzdE5hbWUiOiIxIiwiaXNzIjoibGVhcm5lciIsImlhdCI6MTcwMjAxOTcyNywiZXhwIjoxNzAyNjI0NTI3LCJwcm92aWRlciI6Ik9zYXQiLCJwaWQiOjV9.kXvAqJGqR9jjDTobzlwQ4k_sLl0aFWvEIeST93elODA",
      "Windows",
      "Chrome"
    ]
  },
  "status": "TOO MANY SESSIONS"
}
1

There are 1 answers

0
Dmitri T On BEST ANSWER

In case if attribute name is dynamic you can always go for wildcard operator like *

If you want to extract this guy:

eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJpZCI6IjY5ODAiLCJlbWFpbCI6IkBAc3ViamVjdCsxQG9zYXQuY29tK29zYXQiLCJmaXJzdE5hbWUiOiIxIiwiaXNzIjoibGVhcm5lciIsImlhdCI6MTcwMjAxOTcyNywiZXhwIjoxNzAyNjI0NTI3LCJwcm92aWRlciI6Ik9zYXQiLCJwaWQiOjV9.kXvAqJGqR9jjDTobzlwQ4k_sLl0aFWvEIeST93elODA

The relevant JsonPath query would be something like:

active.*.[0]

Demo:

enter image description here

More information: How to Use the JSON Extractor For Testing