# Ember data serialzier

**URL:** <https://discuss.emberjs.com/t/ember-data-serialzier/8109>\
**Category:** Ember Data\
**Created:** [June 1, 2015, 3:58am UTC](https://discuss.emberjs.com/t/ember-data-serialzier/8109 "2015-06-01T03:58:40Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![three\_accents](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@three\_accents](https://discuss.emberjs.com/u/three_accents)\
**Post date:** [June 1, 2015, 3:58am UTC](https://discuss.emberjs.com/t/ember-data-serialzier/8109/1 "2015-06-01T03:58:40Z")

</div>

I have a pre-built JSON api. Here is an example of the payload:

item:

```
{
    "data": {
        "id": 1,
        "username": "rodzzlessa",
        "slug": "rodzzlessa"
     }
}

```

collection:

```
{
"data": [
    {
        "id": 34,
        "name": "HDG common nails 50lbs",
        "slug": "hdg-common-nails-50lbs4569",
        "description": "Accusantium ipsam impedit omnis sint dolorum.",
        "image_src": "nail-box-angle.png",
        "categories": {
            "data": [
                {
                     "id": 2,
                     "name": "nails",
                    "image_src": "nails-icon.png"
                }
             ]
         }
     }
  ]
}

```

I know I need to create a custom ember data serializer. I’m just having trouble understanding actually how to do it. I looked online but there are no good resources/tutorials. Is there an ember data book? or online resource to help me with my issue? From what I understand I need to edit the extractArray and extractSingle methods. I saw the ember-data API guide but it was just confusing I have no idea what to do. If anyone could point me to any good resource on the topic I would really appreciate it. Thank you

---

<div class="post-metadata">

**Author:** ![three\_accents](https://avatars.discourse-cdn.com/v4/letter/t/a3d4f5/32.png) [@three\_accents](https://discuss.emberjs.com/u/three_accents)\
**Post date:** [June 1, 2015, 4:08pm UTC](https://discuss.emberjs.com/t/ember-data-serialzier/8109/2 "2015-06-01T16:08:41Z")

</div>

I have been able to create a per model basis serializer which works for now. The only problem I’m having is dealing with relationships:

```
export default DS.RESTSerializer.extend(DS.EmbeddedRecordsMixin, {
	extractArray: function(store, typeClass, payload) {
	    payload.products = payload.data;
	    delete payload.data;

	    return this._super(store, typeClass, payload);
	}
});

```

I have a `categories: DS.hasMany('category')` now I’m trying to figure out which method to edit to let the payload know that they need to be grabbing `categories.data` instead of just `categories` since its not an array.

---

<div class="post-metadata">

**Author:** ![alekseev\_leo](https://avatars.discourse-cdn.com/v4/letter/a/4491bb/32.png) [@alekseev\_leo](https://discuss.emberjs.com/u/alekseev_leo)\
**Post date:** [June 5, 2015, 11:01pm UTC](https://discuss.emberjs.com/t/ember-data-serialzier/8109/3 "2015-06-05T23:01:22Z")

</div>

Sorry, this is probably slightly off topic and might not cover your case, but the following slides could be beneficial: [Feed Normalization with Ember Data 1.0](http://www.slideshare.net/JeremyGillick/normalizing-data). The basic idea is to side-load the relationships.
