0

I'm trying to format the serialized output from the active_model_serializers gem as key/value pairs.

By default, ActiveModel::Serializer renders an output like this:

[
  {
    "id": 1,
    "value": "foo"
  },
  {
    "id": 2,
    "value": "bar"
  }
]

I'm looking to format the output like this:

{
  1: {
    "value": "foo"
  },
  2: {
    "value": "bar"
  }
}

Is this possible using active_model_serializers?

Synthead
  • 2,162
  • 5
  • 22
  • 25

1 Answers1

0

It seems that active_model_serializer is following 1.0 of the format specified in jsonapi.org/format. I don't think you can do something like that, maybe you can try jbuilder or rabl

PS: Actually I have this problem, too. I can't figure it out by using active_model_serializer, If you have fixed this, please let me know.

ShallmentMo
  • 449
  • 1
  • 4
  • 15