Angappan Ganesan
Angappan Ganesan

Reputation: 49

Export Json response to a file in Karate Framework

I created a java util function, which gets Json response and writes to a text file.

Java Code:

 public void write(String str, String path) {
            File f = new File(path + "\\Log.txt");
            try {
                Files.write(str.toString().getBytes(), f);
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

However, when I looked on the text file, it is not is proper json format. Nodes are not within in Quotation marks.

Sample Response:

  {
    name=Abc, 
    id=123, 
    statusCode=200
    }

Can someone give a work around to convert it to proper json format.

Upvotes: 2

Views: 4128

Answers (1)

Peter Thomas
Peter Thomas

Reputation: 58058

You have got a reference to a Java Map not JSON.

Please read this, it should make it clear: https://github.com/intuit/karate#type-conversion

So try to do something like this first. I'm guessing here because you haven't provided enough info:

* string json = response
* MyCode.write(json)

Upvotes: 1

Related Questions