Forum Discussion

jayagarw's avatar
jayagarw
New Contributor
8 years ago

How to Create a JSON Array from Results at JDBC Test Step in SOAPUI NG Pro

Hi Team

 

I have a Requirement to create a JSON payload from JDBC Test Step Values dynamically and send it as Request to my rest service. How Can I write the groovy script to fetch the values from JDBC Test Step.

 

Sample

 

<Results>
      <ResultSet fetchSize="10">
            <Row rowNumber="1">
                   <ORDERID>H001</SOURCEORDERID>
                   <LINEID>L001</SOURCELINEID>
                   <HOLDID>1</HOLDID>
                   <HOLDNAME>HOLDA</HOLDNAME>
                   <RELEASED_FLAG>N</RELEASED_FLAG>
            </Row>
            <Row rowNumber="2">

                   <ORDERID>H001</SOURCEORDERID>
                   <LINEID>L001</SOURCELINEID>
                   <HOLDID>2</HOLDID>
                   <HOLDNAME>HOLDB</HOLDNAME>
                   <RELEASED_FLAG>N</RELEASED_FLAG>

            </Row>

            <Row rowNumber="3">

                   <ORDERID>H001</SOURCEORDERID>
                   <LINEID></SOURCELINEID>
                   <HOLDID>3</HOLDID>
                   <HOLDNAME>HOLDC</HOLDNAME>
                   <RELEASED_FLAG>N</RELEASED_FLAG>

            </Row>

      </ResultSet>
</Results> 

 

Thanks 

Jayant Agarwal

    • jayagarw's avatar
      jayagarw
      New Contributor

      Hi Rao

       

      I wanted to create the JSON as below as This is dynamic based on number of records fetched from the query. Reqyestpayload attribute is of type JSONArray

       

      {
      "requestPayload": [
             {
                   "ORDERID": "H001",
                   "LINEID": "L001",
                   "HOLDID": "1",
                   "HOLDNAME": "HOLDA",
                   "RELEASED_FLAG": "N"
            },
            {
                   "ORDERID": "H001",
                   "LINEID": "L001",
                   "HOLDID": "2",
                   "HOLDNAME": "HOLDB",
                   "RELEASED_FLAG": "N"
            },
            {
                   "ORDERID": "H001",
                   "LINEID": null,
                   "HOLDID": "3",
                   "HOLDNAME": "HOLDC",
                   "RELEASED_FLAG": "N"
            }
         ]
      }

       

      Thanks

      Jayant Agarwal