Hi, I want to format all the json files in a folder using groovy script. can someone please help me.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I want to format all the json files in a folder using groovy script. can someone please help me.
Hi,
I want to format all the json files in a folder using groovy script. can someone please help me. I tried with pretty print method it is not working.
Method used is as below :
printResponseWriter.prettyprint(jsonResponseContent).
Thanks.
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
try this.
import groovy.json.*;
def jsonSlurper = new JsonSlurper()
String filePath = "C:\\result.json"
def object = jsonSlurper.parse(new File(filePath))
def json = JsonOutput.toJson(object)
def pretty = JsonOutput.prettyPrint(json)
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
Hi,
Thanks for the solution. Formatted text is printing on the console. But can we format file itself. Please let me know on this.
Thanks
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
try this
import groovy.json.*;
def jsonSlurper = new JsonSlurper()
String filePath = "C:\\DevCode\\lgs-nimbus\\result.json"
def object = jsonSlurper.parse(new File(filePath))
def json = JsonOutput.toJson(object)
def pretty = JsonOutput.prettyPrint(json)
File file = new File(filePath)
file.write(pretty)
