I’m using renderJSON() method to return an array of objects, with a custom JsonSerializer for the class of each element. The response has the following format:
[{"id":2,"name":"fred"},{...},...]
But I would like to add the name of the array at the begginning:
"arrayname":[{"id":2,"name":"fred"},{...},...]
How can I add the name of the object to a JSON response with renderJSON()? Should I use a template or can I do it with java code?
looks like invalid Json, but if you wrap the array in an object you could get:
E.g. something like this:
Then you can call
renderJSON(new MyArrayWrapper(yourUserArray));to get JSON like: