Rendering JSON with formatting « Intelligrape Groovy & Grails Blogs

Rendering JSON with formatting

Posted by

In Grails, We often use

render list as JSON.

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

def json = doc as JSON
json.prettyPrint = true
json.render response

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

This entry was posted on July 16th, 2012 at 3:58 pm and is filed under Grails . You can follow any responses to this entry through the RSS 2.0 feed. You can leave a response, or trackback from your own site.

2 Responses to “Rendering JSON with formatting”

Leave a Reply