10.1.8.2 Creating JSON Views - Reference Documentation
Authors: Graeme Rocher, Peter Ledbrook, Marc Palmer, Jeff Brown, Luke Daley, Burt Beckwith, Lari Hotari
Version: 3.1.4
10.1.8.2 Creating JSON Views
JSON views go into thegrails-app/views
directory and end with the .gson
suffix. They are regular Groovy scripts and can be opened in any Groovy editor.Example JSON view:json.person {
name "bob"
}
Tip: To open them in the Groovy editor in Intellij double click on the file and when asked which file to associate it with choose "Groovy"The above JSON view produces:
{"person":{"name":"bob"}}
json
variable which is an instance of StreamingJsonBuilder.Example usages:json(1,2,3) == "[1,2,3]" json { name "Bob" } == '{"name":"Bob"}' json([1,2,3]) { n it } == '[{"n":1},{"n":2},{"n":3}]'