As a part of my RESTful API I found myself needing to return a json with "variable" keys, I'll try to make things more clear with a simple example:
I have different groups, each group has a group_id
, so the expected return would be:
{
1: {
"name": "first_group_name",
...
},
5: {
"name": "second_group_name",
...
}
}
As you can see, the keys (group_id
s) in the root json are not something I can hard-code in my model, all I know is they are integers.
Can anyone help with a solution to this problem?
I am not sure this is what you need but you can do something like this:
if you are using you can modify the code as you want.