Category Archives: JSON

How to save list of JSON objects to Grails domain and render it?

To get JSON from request(POST) do following:

Request-type: POST


name : "TestName"

surname: "TestSurname"


We can post JSON data from Postman REST client.


class person{

String name;

String surname;



import grails.converters.deep.JSON
import groovy.json.JsonSlurper

class PersonController{

def saveJsonToDomain(){

String jsonObject = request.getJSON();                                                                      // get JSON data from request body
println “jsonObject : ” + jsonObject;
def jsonList = new JsonSlurper().parseText(jsonObject);
println “jsonList.size() : ” + jsonList.size();
for(jsonObj in jsonList){
Person person = new Person(jsonObj);; // save JSON directly to grails domain
render person as JSON // render JSON object
catch(Exception e){
render “Error saving category : ” + e;



Don’t forget add the json data with same name as variable names in domain.

ProsperaSoft offers Grails development solutions. You can email at to get in touch with ProsperaSoft Grails experts and consultants.