Forum Discussion

noegh_mmi's avatar
noegh_mmi
Occasional Contributor
7 years ago

How to Trim Json Response and Parse the Data to the next Step in the Test Case

Json Response in Step 1 = iaa.service.response/v2/policy/4512650

I only want to use the number 4512650 and parse it to the next Step in the Test case

2 Replies

  • nmrao's avatar
    nmrao
    Champion Level 3

    In case if that is just a string and need to extract the value?

     

    def str = 'iaa.service.response/v2/policy/4512650'
    //Get the id
    def policyId =  str.substring(str.lastIndexOf('/')+1, str.size())
    //Save it at test case level custom property for later use
    context.testCase.setPropertyValue('POLICYID', policyId)

    In the next step, use property expansion i.e., ${#TestCase#POLICYID} where every it is needed

  • nmrao's avatar
    nmrao
    Champion Level 3
    noegh_mmi,

    Was that the whole response? or just a string and you want to extract that value?

    Or was it a resource path you mentioned?
    Or you want to access it in the mock service script dispatcher?
    Please clarify.