Forum Discussion

Renuka's avatar
Renuka
Occasional Contributor
7 years ago
Solved

How to read JSON data from file and use it in request body ?

I have one JSON file which contains following data:
{
  "registrationKey": "sadnskjadsdkfj",
  "firstName": "Renuka",
  "lastName": "Saini",
  "email": "reom@gmail.com",
  "phone": "1234567890",
  "notes": "testing",
  "isvApiKey": "87779"
}

 

This data I need to put in one of the api's request body. Can anybody help be how to load this data using data source 'JSON'?

  • I'm sorry but I do not have experience of the JSON data source (The vast majority of my SoapUI use is with XML data).

     

    If you haven't already I suggest you read the documentation section on Data Driven Testing, this has a lot of useful information, in particular the JSON Data Source section. It looks like you could set your File Wait test step as the source of the JSON data (Please Note: I have not tried or tested this).

10 Replies

  • Radford's avatar
    Radford
    Super Contributor

    Has you investigated using the File Wait test step to read your file? The contents of the file will be put into the file wait test step property "fileContent" which you can then access in the normal ways.

    • Renuka's avatar
      Renuka
      Occasional Contributor

      I am a beginner in Soap UI. Can you please mention the steps to read data using FileWait test step?

      Thanks in advance

      • Radford's avatar
        Radford
        Super Contributor

        Exactly as nmrao said, add the File Wait test step before your Rest request and then in the Rest request reference the data from the File Wait test step with a property expansion (a property expansion is the ${ ... } thing that nmrao mentions) 

         

        If you are new to SoapUI, are you aware of the "point and click" Get Data functionality. This will allow you to use the GUI to reference data form one step to another Note: The point and click functionality is actually just a way to create the property expansions that nmrao mentioned via the GUI.

         

        There is an alternative to using the property expansions, you could put a Property Transfer test step between your File Wait and Rest test step and then configure to transfer the file contents. Try both methods and pick the one you are most comfortable with.

         

        Please note: My answers have assumed that you wanted to copy the entire contents of the file into the request body.