6

How do I extract the json object name from the below json data in Jmeter

[
:   {
:   :   "name":"x",
:   :   "age":"50",
:   :   "gender":"Female"
:   }
]

I am doing this $..name in the JsonPath Extractor which is giving me this in the variable I extracted to

name=["x"]

Is there a way I could just get name=x without the array format

Or is there a way I can extract just the x from ["x"]?

Thanks

7
  • Did you try via the index? $..name[0] Commented Jun 6, 2017 at 18:17
  • yes, that's not extracting anything Commented Jun 6, 2017 at 18:18
  • Then, try ${name_1} after getting the array with $..name. Commented Jun 6, 2017 at 18:19
  • @WiktorStribiżew - yeah, using String newName= vars.get("name_1"); in the beanshell post processor is giving me newName as just x but when I am trying to use newName in other requests by passing as ${newName} it is being passed as ${newName} only but not it's value x Commented Jun 6, 2017 at 19:25
  • Isn't that supposed to be passed as ${__V(${newName})}? Commented Jun 6, 2017 at 19:46

3 Answers 3

3

You may use

 ${name_1} 

after getting the array with 

$..name
Sign up to request clarification or add additional context in comments.

Comments

2

You need to get name attribute from the first object in the array therefore you need to amend your JSON Path expression to look like $[0].name

References:

Comments

2

Using this in a bean shell post processor worked

 String newName = vars.get("name"). replace([","").replace("]","").replace("\"","");
log.info("name is: " +newName);

which gives name is: x

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.