Forum Discussion

Gangadhar's avatar
Gangadhar
Occasional Contributor
8 years ago

How to convert Datasource values(Data) to json array in Post request body?

Hi,

     Can you please advise how to take a list of values (e.g. in Excel) and then convert that to json array. I am getting values from excel in DataSource but I am unable to convert those values to json array in request body editor.. Please find the attachments.

In request body I need json like below

[ { "tcId":"ab_5",

"tcName":"ab5",

"tcDesc":"abc5",

"tcType":"Other",

"tcPriority":"Low" }]

Can anybody help me to get json array as above in post request editor from Datasource ?

Thanks & Regards,

Gangadhar Badagi

2 Replies

  • Radford's avatar
    Radford
    Super Contributor

    I do not know if this is the best method as I don't have a lot of experience with JSON, but as no one has answered your questions this might help. If anyone knows a better way please step in!

     

    You should be able to process your data between your DataSource and REST test step within a Groovy Script test step.

     

    You can get your data from you DataSource test step into the Groovy test step with the Ready API point and click Get Data functionality.

     

    Once you have your data within your Groovy Script, you could use the Groovy JSON functionality to produce and output your data (I've got to admit I haven't used this, you will have to follow the link and read up).

     

    The once you have your new JSON text string, you can update you REST request something like:

     

    import com.eviware.soapui.support.GroovyUtils
    
    def groovyUtils = new GroovyUtils(context)
    groovyUtils.setPropertyValue('REST Request Test Step Name', 'Request','Insert JSON Text String here')

     

    Please Note: the above code is not tested, thus may need adjusting for your situation.

     

    Hopefully this will get you started.

    • Gangadhar's avatar
      Gangadhar
      Occasional Contributor

      Hi,

      Thank you Radford for reply. I will try with your code.

       

      Thanks & Regards,

      Gangadhar Badagi