Forum Discussion

sainandam's avatar
New Contributor
6 years ago

ReadyAPI- Datasink - How to save multiple rows from response into CSV file.

I am trying to map the JSON response attributes with respect to the fields in a test step called Datasink in order to export it in CSV. All i can create is adding columns for the response attributes. i am looking for a help to add the data from repeating attributes in single column by adding rows underneath instead of adding more columns.




"Id" : "123",
      "Name" : abc,
      "ShortName" : abc,

"Id" : "234",
      "Name" : bdc,
      "ShortName" : bdc,


expected CSV from datasink

ID         Name

123       ABC

234       BCD


2 Replies

  • richie's avatar
    Community Hero

    Hi sainandam


    I'm also using a datasink in almost the same way and so when I read your post - I thought "whats the problem?"


    But after having another look at my script and the page (datasink page in - I can see the difference between my script and what yours is doing.


    My script is successfully writing new records in my datasink file as rows rather than columns and that's what you are talking about - right? 

    I think I know why it's doing this - its because you have multiple records in your json response. 


    My script returns a json response with a single record (whereas your response returns multiple records) transfers the attributes to some properties, which are then sourced via the datasink to a flat file, and then I have a dataloop step going back to the rest request which generates my response and repeats - each time writing a new record in a new row in my datasink file.


    I had a look in the page I've referenced above just in case there was a certain option like 'append to file' but something more appropriate, but I don't think the OOB functionality on datasinks enables you to do what you want - i.e. write out multiple records in your json response into rows rather than columns in your datasink file.


    I've only played around with the datasink functionality a little before now, so I could be mistaken - but I as I say above - I dont think the datasink functionality does what you want - so you have as far I can tell - 2 choices.  Use groovy to handle this (which would probably be quite easy for a scripter - afraid I can't help you there!) or the other choice is to alter your REST request resultset via additional parms to restrict the number of records that are returned in your .json response.


    I'm sorry I couldn't be of more help - but at least you now know why the datasink function is working this way!