Forum Discussion

richie's avatar
richie
Community Hero
2 years ago
Solved

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 ...
  • ChrisAdams's avatar
    2 years ago

    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());