-2

I have this controller:

respond :Alert.list()

It gives:

[{id: ..}, {id: ..}]

What I want:

{"alerts":[{"id":...}. {id:..}]}

How do I let the respond make into the format I want? I don't want to have a custom JSON marshaller as my dataset is big.

What will be the outcome if I do the following than having a custom marshaller?

def o = new JSONObject()
def arr = new JSONArray()
def a = new JSONObject()

alerts.each{
    a.put("id",it.id)
    ...
    arr.add(a)
}
o.put("alerts",arr)
respond o
1
  • 1
    It seems that you forgot to ask a question.
    – Unihedron
    May 16, 2015 at 7:56

1 Answer 1

0

Try it like this:

  //do your filtering here to get alertList


respond: [alerts: alertList]
6
  • can not. this is a map in a index operation
    – user903772
    May 16, 2015 at 8:46
  • 1
    what do you mean by that? I did not get you
    – dsharew
    May 16, 2015 at 8:56
  • IF I do your way, I cant exclude properties
    – user903772
    May 16, 2015 at 9:37
  • well I did not see any filtering on ur question, updated the answer.
    – dsharew
    May 16, 2015 at 9:58
  • is there an easy way to exclude properties?
    – user903772
    May 16, 2015 at 10:12

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.