Getting JSON data on server side with Grails

maximus picture maximus · Jun 11, 2010 · Viewed 24.5k times · Source

Once I post JSON data to a url in Grails, how can I get access to that data inside of the controller?

Answer

Daniel Rinser picture Daniel Rinser · Jun 14, 2010

Grails automatically parses/unmarshals the JSON and you can access it via request.JSON in your controller. The object returned is of type JSONObject and thus allows map-style access to the properties. You can also directly use this JSONObject for data binding:

def jsonObject = request.JSON
def instance = new YourDomainClass(jsonObject)