How to extract partial string value from response ?

arunice17arunice17 Posts: 3

I am getting my response as below format and i want to exact partial string value and send to other call

root
{
"countries" : { "States" : " {\"city": xyz}"
} }

From Above response , i want value "xyz" into my databank and will send this value(xyz) to another API call.

How to do this extraction?

Comments

  • benken_parasoftbenken_parasoft Posts: 895 ✭✭✭
    edited October 2019

    It looks like the value of the "States" property is a JSON string. Are you saying that JSON string contains an encoded JSON object like this?

    {
        "countries" : {
            "States" : "{\"city\": \"xyz\"}"
        }
    }
    

    If so, you would use two JSON Data Banks.

    The first JSON Data Bank would need to extract the value of the "States" property. The extraction would be something like /root/countries/States/text(). Let's also say you name the data bank column for the extraction "Test 1: States".

    The second JSON Data Bank would take the value of the first extraction as input. To do this, simply type "${Test 1: States}" in the text field of the data bank's Input tab. Next, create an extraction for the value of the "city" property. The extraction would be something like /root/city/text(). Let's also say you name the data bank column for the extraction "Test 2: city".

    Your "Test 2: city" data bank column can now be referenced in a later test, wherever you need to use it, like in a REST Client.

Sign In or Register to comment.