Write Out full Response to an external file?
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2022
03:41 AM
06-24-2022
03:41 AM
Write Out full Response to an external file?
Hey!
I need a little help if that's ok - one of my APIs returns the full openAPI definition as the response to one of my requests.
I'm trying to write out the contents of the response to a file (i.e. latestOpenAPI.json), so that I can then load it into swagger editor - but I'm getting "no signature of method" on the file write. I've spent the last hour tinkering with it - and I can't get it to work - would someone be able to have a look and indicate where I'm going wrong please?
import groovy.json.JsonSlurper
import java.io.File
def resp = context.expand( '${REST Request#Response}' ).toString();
def response = new JsonSlurper().parseText(resp);
new File("D:/OAS/latestOpenAPI.json").write( response )
The above is what I've got so far.....
Cheers!
Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
Solved! Go to Solution.
3 REPLIES 3
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2022
04:18 AM
06-24-2022
04:18 AM
Hi,
This works for me....
import groovy.json.JsonSlurper
import java.io.File;
def resp = context.expand( '${Some Request#Response}' ).toString();
def response = new JsonSlurper().parseText(resp);
log.info(response.toString());
// I'm on Windows, escape the double backslash
File myFile = new File("c:\\Temp\\json2.json");
// Reponse might 'log', but its not a string. Stringify it.
myFile.write(response.toString());
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2022
04:59 AM
06-24-2022
04:59 AM
That's brilliant! Cheers fella!
Rich
if this helped answer the post, could you please mark it as 'solved'? Also if you consider whether the title of your post is relevant? Perhaps if the post is solved, it might make sense to update the Subject header field of the post to something more descriptive? This will help people when searching for problems. Ta
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
06-24-2022
05:51 AM
06-24-2022
05:51 AM
You're welcome
