Forum Discussion
Hi richie
Hope this helps. Don't want to give away the full listing.
I ran the full functional test and it only output 1 value when there should be a few thousand. it comes down to an array on the output from this datasource. I can look towards a Groovy script but if ReadyAPI provides it without scripting, even better.
Cheers i just needed to appreciate the basic structure, so the bookings attribute is either an object or array and it contains repeating objects which contains a bookingId attribute and you want to save off the bookingId attribute values.....right?
Yeah, its gonna need some groovy i reckon. The way you have setup the datasource has a single transfer property....each one would park off a single bookingId. I dont see any way of doing it....especially as you say there could be many and the number isnt fixed.
Dunno if anyone else can think of any other non groovy options, but i cant!
Ta
Rich
- davecoleman4 years agoContributor
thanks richie . ill do some work on this and report back....
- davecoleman4 years agoContributor
Hi,
So I've used JsonSlurper to view the response and have extracted the related records to the Log.
Now how do I pass each into an array / list to export via the Datasink?
import groovy.json.* import groovy.util.* def json='[{ "message" : "Success", "bookings" : [ { "bookingId" : 60002172, "bookingDate" : "1900-01-01T00:00:00" }, { "bookingId" : 59935582, "bookingDate" : "1900-01-01" }, { "bookingId" : 53184048, "bookingDate" : "2019-01-15", "testId" : "12803798123", "overallScore" : "PASS" }, { "bookingId" : 53183765, "bookingDate" : "2019-01-15T13:45:00" }, { "bookingId" : 52783312, "bookingDate" : "1900-01-01" } ] } ]' def response = context.expand( json ) def parsedjson = new groovy.json.JsonSlurper().parseText(response) log.info parsedjson log.info " Count of records returned: " + parsedjson.size() log.info " List of bookingIDs in this response: " + parsedjson.bookings*.bookingId
Any pointers would be appreciated. I could also work with exporting the list here on each iteration of the loop to a CSV file. but it would be good to know how a property could be created to use.
- nmrao4 years agoChampion Level 3What is your use case?
Are you going to use the saved data in any way later? And how?
For the above sample data how you want to see in the saved file? Sample please with columns and rows?
Related Content
Recent Discussions
- 14 days ago
- 21 days ago