Unable to get Rest Response in JSON format using Groovy
SOLVED- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Unable to get Rest Response in JSON format using Groovy
Hi All,
I have created successfully a test suite with Rest API and I have created groovy script to save request,response in the Local.
Problem what I am facing is I am not getting Rest Response is JSON format in the Local. But I get Request in JSON format.
Please refer the attachments for better understanding.
Apprecaite if anyone can help me in resolving this.
.
Solved! Go to Solution.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
However you are getting your response as a String, you can get the human readable JSON by prettyprinting it:
response.with(groovy.json.JsonOutput.&prettyPrint)
Then write that version to the File.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Can you post your code? Then I can show you where to apply the changes.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
response.with(groovy.json.JsonOutput.&prettyPrint) res.write(response,"UTF-8")
Change this like this:
response = response.with(groovy.json.JsonOutput.&prettyPrint)
res.write(response,"UTF-8")
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi JHunt,
I have implemented by adding a jar file(groovy-json-2.1.1.jar) and to add syntax def JsonResponse = JsonOutput.prettyPrint(response)using groovy.
I achieved the result as expected
