Need to extract the key value from json multidimensional array

Viewed 54
{
   "jsonrpc":"2.0",
   "id":313193812,
   "result":[
      [7, "89 NISA SCHOOL - 2 School"],
      [12, "1014 NISA Foundation - Andheri School"],
      [13, "1015 NISA Foundation - Bandra School"],
      [14, "1016 NISA Foundation - Juhu School"],
      [15, "1017 Pharo Foundation - Dahisar School"],
      [19, "1013 Nisa School - 143 School"],
      [20, "1011 Nisa School - 456 School"],
      [21, "1012 Nisa School - 789 School"]
   ]
}

instead of using index value like show in the below,i need to extract the key value 89,with where condition as school name(school name to be input from excel)

enter image description here

2 Answers

Try this:

{
   "jsonrpc":"2.0",
   "id":313193812,
   "result":[
      [7, "89 NISA SCHOOL - 2 School"],
      [12, "1014 NISA Foundation - Andheri School"],
      [13, "1015 NISA Foundation - Bandra School"],
      [14, "1016 NISA Foundation - Juhu School"],
      [15, "1017 Pharo Foundation - Dahisar School"],
      [19, "1013 Nisa School - 143 School"],
      [20, "1011 Nisa School - 456 School"],
      [21, "1012 Nisa School - 789 School"]
   ]
}

if(result[0][1] === "89 NISA SCHOOL - 2 School"){
 console.log(89);
}

89 is not the "key", it's a part of "value", see JSON specification for more details, therefore you won't be able to extract it using either JSON Extractor or JSON JMESPath Extractor, you will need to go for the regular expressions like:

"(\d+)\sNISA SCHOOL - 2 School"

Demo:

enter image description here

You can replace NISA SCHOOL - 2 School with a JMeter Variable from your CSV file like:

"(\d+)\s${school}"
Related