Service Virtualization

  • 1.  How to extract value from the response?

    Broadcom Employee
    Posted Jun 01, 2018 06:13 AM

    Hi,

     

    I have following response, from the response I need to store uiId value in a variable and I need to extract the integer value present in the URL: https://rally1.rallydev.com/slm/webservice/v2.0/defect/226117691672 and store in a variable.

     

    Is there a way to do this?

     

    [
        {
            "objectId" : "https://rally1.rallydev.com/slm/webservice/v2.0/defect/226117691672",
            "uiId" : "DE1087317"
        }
    ]

     

    Regards

    Irfan



  • 2.  Re: How to extract value from the response?
    Best Answer

    Posted Jun 01, 2018 09:47 AM

    Would a JSON path filter not select "uiId"? 

    For example: 

    $.[0].uiId to get the uiID and

    $.[0].objectId but this does not extract only the integer value in the url.

     

    For retrieving the integer value, you might review the Create Property based on Surrounding Value filter to extract the integer value from the URL. Refer to: Create Property Based on Surrounding Values - DevTest Solutions - 10.1 - CA Technologies Documentation  

     

    What happens if the response list has more than one occurrence?

    If so,

    you may have to iterate over the list... (e.g., count number of items in the list)

    iterate over the list with a counting dataset (e.g., from 0 by one until > than count of items - 1 using value INDEX)

    filter each elements' value (e.g., $.[{{INDEX}}].uiId, and so on) 

    deal with each row in the list (e.g., substring out the integer value...)



  • 3.  Re: How to extract value from the response?

    Broadcom Employee
    Posted Jun 01, 2018 09:50 AM

    In the test step that gets that response block, you want a couple of JSONPath filters. The first one creates your property for ulid:

    The second one extracts the objectID for you to parse later:

    You then want a quick JSR-223 script step to extract the property from your objid: