Search code examples
jsonrestgroovysoapsoapui

Assign child node from a JSON response to project variable everytime a request is sent in SoapUI


I am new to soapUI and still figuring it out. Is it possible to extract data from a JSON response and assign it to a project variable which can further be used in another request. In my case it's an authentication token.

Appreciate all your responses.

Found nothing specific on internet regarding this.


Solution

  • I did it using property transfer.

    Add a property transfer step, and select the response of the previous REST request, and use Xquery to get the child node, and assign it to the project variable.

    For eg:

    {"menu": {  
      "id": "file",  
      "value": "File",  
      "popup": {  
        "menuitem": [  
          {"value": "New", "onclick": "CreateDoc()"},  
          {"value": "Open", "onclick": "OpenDoc()"},  
          {"value": "Save", "onclick": "SaveDoc()"}  
        ]  
      }  
    }}
    

    Use the Xquery, "$.menu.popup.menuitem.value", to access the respective child node.