Friday, February 22, 2013

Grails pretty print using deep JSON Converter

Here's a simple little Grails code sample to enable pretty printing on your JSON Converter when using the deep option:
def index() {
    def all = Product.list()
    withFormat {
        json {
            JSON.use("deep"){
                def c = all as JSON
                c.prettyPrint = true
                render c
            }
        }
        xml {
            XML.use("deep"){  
                render all as XML 
            }
        }
    }
}
After figuring this out I also discovered the JSON View extension for Chrome, which negated my need for pretty printing JSON.

No comments:

Post a Comment