Solved
Forum Discussion
richie
Community Hero
Hey davecoleman,
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
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
davecoleman
4 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?- sonya_m4 years agoSmartBear Alumni (Retired)
Richie, nmrao, thank you for your help!
Hi davecoleman ! Were you able to solve this? Please share your solution with the Community if you were.
Otherwise, please either provide nmrao with the info they are requesting or, alternatively, contacting support can bring clarity to this, as well.