# How to normalize backend responses in new Json API serializer?

**URL:** https://discuss.emberjs.com/t/how-to-normalize-backend-responses-in-new-json-api-serializer/8305
**Category:** Ember Data
**Created:** [July 3, 2015, 11:55am UTC](https://discuss.emberjs.com/t/how-to-normalize-backend-responses-in-new-json-api-serializer/8305 "2015-07-03T11:55:34Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![mauricioac](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mauricioac/32/10464_2.png) [@mauricioac](https://discuss.emberjs.com/u/mauricioac)
#### Post date: [July 3, 2015, 11:55am UTC](https://discuss.emberjs.com/t/how-to-normalize-backend-responses-in-new-json-api-serializer/8305/1 "2015-07-03T11:55:34Z")

</div>

Hello once again everyone,

So, we have a User model which has a relationship with Employee. on the frontend the relationship is called `profile`, and in the past (before json api), we used `attrs` on serializer to match the fields.

But now, I can’t make it recognize the relationship. I tried the `normalizePayload` and `normalize` hooks on the serializer, changing payload keys, but doesn’t seem to work.

And there’s no documentation, so how should I be normalizing the backend payloads reliably?

---

<div class="post-metadata">

### Author: ![mauricioac](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mauricioac/32/10464_2.png) [@mauricioac](https://discuss.emberjs.com/u/mauricioac)
#### Post date: [July 3, 2015, 12:16pm UTC](https://discuss.emberjs.com/t/how-to-normalize-backend-responses-in-new-json-api-serializer/8305/2 "2015-07-03T12:16:31Z")

</div>

Oh, BTW, forgot to mention that I have tried using the `normalizeResponse` hook on the User model, but the relationships object on the payload is empty.

I assumed Ember Data would send it through the employee serializer, but it didn’t.

---

<div class="post-metadata">

### Author: ![ToddSmithSalter](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/toddsmithsalter/32/12772_2.png) [@ToddSmithSalter](https://discuss.emberjs.com/u/ToddSmithSalter)
#### Post date: [July 3, 2015, 5:48pm UTC](https://discuss.emberjs.com/t/how-to-normalize-backend-responses-in-new-json-api-serializer/8305/3 "2015-07-03T17:48:14Z")

</div>

Which serializer were/are you using? I’ve switched to the new serializer API using the REST Serializer. Had to change `extractSingle` → `normalizeSingleResponse` and `extractArray` → `normalizeArrayResponse`. The methods for accessing model type of changed.

---

<div class="post-metadata">

### Author: ![mauricioac](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mauricioac/32/10464_2.png) [@mauricioac](https://discuss.emberjs.com/u/mauricioac)
#### Post date: [July 3, 2015, 6:05pm UTC](https://discuss.emberjs.com/t/how-to-normalize-backend-responses-in-new-json-api-serializer/8305/4 "2015-07-03T18:05:02Z")

</div>

We were using the ActiveModelSerializer, and switched to the new JSON API serializer with new API. I’ve overwritten the normalize hook, and the model being requested get parsed and goes into store fine, but the relationships don’t. Actually I don’t even see the `relationships` object on the param passed

Before we’d only overwrite the `modelNameFromPayloadKey` and it works like a charm. Will give these hooks you mention a try later on, but do they have access to the relationships object from payload?

Not even the IDs, which is what is causing them to not be loaded at all.

Thank you for the quick response.

---

<div class="post-metadata">

### Author: ![mauricioac](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mauricioac/32/10464_2.png) [@mauricioac](https://discuss.emberjs.com/u/mauricioac)
#### Post date: [July 8, 2015, 3:02pm UTC](https://discuss.emberjs.com/t/how-to-normalize-backend-responses-in-new-json-api-serializer/8305/5 "2015-07-08T15:02:43Z")

</div>

@ToddSmithSalter, thank you. Got a baby step forward. Had to override the `extractRelationships` relationships, because the relationship has a dfferent name than the model name.

I guess I’ll have to come up with a solution that works globally on our projects.

---

<div class="post-metadata">

### Author: ![efx](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/efx/32/17920_2.png) [@efx](https://discuss.emberjs.com/u/efx)
#### Post date: [July 27, 2015, 5:28pm UTC](https://discuss.emberjs.com/t/how-to-normalize-backend-responses-in-new-json-api-serializer/8305/6 "2015-07-27T17:28:50Z")

</div>

I found this blog post useful for how to use the new serializer hooks. It also describes what renaming you’ll need to do for existing `extract` hooks.

> **[Ember Data v1.13 Released](https://blog.emberjs.com/ember-data-1-13-released/)**
>
> We are proud to announce the release of Ember Data 1.13. This represents the first stable release of Ember Data since its creation over 3 years ago. As we explained in the...

---

<div class="post-metadata">

### Author: ![Lelique](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/lelique/32/10359_2.png) [@Lelique](https://discuss.emberjs.com/u/Lelique)
#### Post date: [August 31, 2015, 8:16am UTC](https://discuss.emberjs.com/t/how-to-normalize-backend-responses-in-new-json-api-serializer/8305/7 "2015-08-31T08:16:26Z")

</div>

Hey, guys give an example of normalizeResponse, can’t figure out how to solve simple hasMany serialization.

---

<div class="post-metadata">

### Author: ![mauricioac](https://sea1.discourse-cdn.com/flex019/user_avatar/discuss.emberjs.com/mauricioac/32/10464_2.png) [@mauricioac](https://discuss.emberjs.com/u/mauricioac)
#### Post date: [August 31, 2015, 11:09am UTC](https://discuss.emberjs.com/t/how-to-normalize-backend-responses-in-new-json-api-serializer/8305/8 "2015-08-31T11:09:38Z")

</div>

Honestly, we (my team) gave it up for the time being. So many changes to both backend and frontend was starting to be a time sink.

We’re continuing to use Active Model Serializer. Having no proper documentation at this point, makes it really hard to do the simple things. We’ll wait for the api to settle down and docs be written. Same goes for the transition to Ember 2.0.

Don’t know for JSON API, but have you looked at the EmbeddedRecordsMixin?

> **[EmbeddedRecordsMixin - 4.6 - Ember API Documentation](https://api.emberjs.com/ember-data/release/classes/EmbeddedRecordsMixin)**
>
> Using Embedded Records EmbeddedRecordsMixin supports serializing embedded records. To set up embedded records, include the mixin when extending a serializer, then define and configure embedded (model) relationships. Note that embedded records will...
