# Serialization of deeply nested object

**URL:** <https://discuss.emberjs.com/t/serialization-of-deeply-nested-object/17665>\
**Category:** Ember Data\
**Created:** [March 22, 2020, 9:52pm UTC](https://discuss.emberjs.com/t/serialization-of-deeply-nested-object/17665 "2020-03-22T21:52:55Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karol](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/karol/32/16984_2.png) [@Karol](https://discuss.emberjs.com/u/Karol)\
**Post date:** [March 22, 2020, 9:52pm UTC](https://discuss.emberjs.com/t/serialization-of-deeply-nested-object/17665/1 "2020-03-22T21:52:55Z")

</div>

Hi,

I have a model class Item which looks like this:

```
export default class ItemModel extends Model {
  @attr name;
  @attr description;
  @attr quantityInfo;
}

```

QuantityInfo has some nested attributes but since it is embedded object with no id I don’t want to create another model for it (according to [Defining Models - Ember Data - Ember Guides](https://guides.emberjs.com/release/models/defining-models/#toc_read-only-attributes) ).

I’m connecting with json API which uses snake case so I made ItemSerializer which extends `JSONSerializer.extend(EmbeddedRecordsMixin)`. In this serializer I add method:

```
export default class ItemModel extends Model {
  @attr name;
  @attr description;
  @attr quantityInfo;

  keyForAttribute(key) {    
    return underscore(key);
  }
}

```

.

The problem is that nested attributes are not serialized in the underscore way. This is the output json:

```
{
   "name":"Cola 0.5",
   "description":"asd",
   "quantity_info":{
      "defaultQuantity":0
   }
}

```

Is there any simple solution to solve this problem?

---

<div class="post-metadata">

**Author:** ![joegaudet](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/joegaudet/32/16988_2.png) [@joegaudet](https://discuss.emberjs.com/u/joegaudet)\
**Post date:** [March 22, 2020, 11:50pm UTC](https://discuss.emberjs.com/t/serialization-of-deeply-nested-object/17665/2 "2020-03-22T23:50:47Z")

</div>

Hey Karol,

You should checkout [GitHub - adopted-ember-addons/ember-data-model-fragments: Ember Data addon to support nested JSON documents](https://github.com/lytics/ember-data-model-fragments) allows you to define a schema for your nested object.

Another approach you could take, is to make a custom transform for your type ‘object’ as explained here [Defining Models - Models - Ember Guides](https://guides.emberjs.com/v2.12.0/models/defining-models/#toc_transforms) and transform your keys.

A third approach if you have control of the back end, is to handle transformation of the key space on that side.
