Rendering JSON with formatting

16 / Jul / 2012 by Sachin 0 comments

In Grails, We often use

[java]
render list as JSON.
[/java]

It renders json output without any formatting (spaces and new lines), often we need to provide users an option to receive formatted json (pretty printed) as response, so that it could easily be read and understood by users.

We can easily do that using

[java]
def json = doc as JSON
json.prettyPrint = true
json.render response
[/java]

This renders json in pretty printed format, which is much easier for humans to read and understand.

Thanks

Sachin Anand
sachin[at]intelligrape[dot]com

@babasachinanand

FOUND THIS USEFUL? SHARE IT

Leave a Reply

Your email address will not be published. Required fields are marked *