Retrieving a list of values with GET REST VALUE command

Is it possible to get a list of values?
Here is my sample web response:
{
"mylist": [
{

"translated": "1200",
"quantity": -1

},
{

"translated": "PEAK",
"quantity": -3

}
],
"status": "S",
"message": null
}
I want to get all available values of key "translated" and store them in a list, something like ["1200","PEAK"]
I dont know how many instances of "translated" key will be available in the response.

0
1 comment

Official comment

Avatar
Ahmad Sabah

Hi Manoj,

Please copy the below SLL commands and then navigate to an Automated Test Case > More > Advanced view, and paste them there:

SET VARIABLE sample_value VALUE STATIC "{ \"trackinglist\": [ {  \"translated\": \"1200-Plastic\", \"transaction_quantity\": -1  }, {  \"translated\": \"PEAK\", \"transaction_quantity\": -3  } ], \"status\": \"S\", \"message\": null }" HALT ON ERROR 
LIST_SET LIST_VARIABLE updated_list  SPLIT_STRING REGEX "\"translated\"\\s*:\\s*\"([^\"]+)\"" TEXT_TO_SPLIT @sample_value HALT ON ERROR

The value provided in the SET_VAR command is an example of the variable being set in GET_REST_VALUE, by using that variable in the following SET_LIST command with the Regex code provided, you'll get all the values of key "translated" set into the list.

Please let us know if you need anything else.

Regards,
Subject7 Team

Comment actions Permalink

Please sign in to leave a comment.