Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9150869
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T11:40:09+00:00 2026-06-17T11:40:09+00:00

I have an API that returns JSON that is not properly formatted for Ember’s

  • 0

I have an API that returns JSON that is not properly formatted for Ember’s consumption.
Instead of this (what ember is expecting):

{ events: [
    { id: 1, title: "Event 1", description: "Learn Ember" },
    { id: 2, title: "Event 2", description: "Learn Ember 2" }
]}

I get:

{ events: [
    { event: { id: 1, "Event 1", description: "Learn Ember" }},
    { event: { id: 2, "Event 2", description: "Learn Ember 2" }}
]}

So if I understood correctly, I need to create a custom Serializer to modify the JSON.

var store = DS.Store.create({
    adapter: DS.RESTAdapter.create({
        serializer: DS.Serializer.create({
            // which hook should I override??
        })
    })
});

I’ve read the code comment related to the DS.Serializer, but I can’t understand how to achieve what I want…

How can I do it?

ps: My goal is to make App.Event.find() work. Currently, I get Uncaught Error: assertion failed: Your server returned a hash with the key 0 but you have no mapping for it. That’s why I need to fix the JSON received.

edit: Here’s how I made it work, for now:

extractMany: function(loader, json, type, records) {
    var root = this.rootForType(type),
    roots = this.pluralize(root);

    json = reformatJSON(root, roots, json);
    this._super(loader, json, type, records);
  }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T11:40:10+00:00Added an answer on June 17, 2026 at 11:40 am

    I am assuming that the responses contain the IDs only, and that you are trying to extract them.

    You will want to subclass DS.JSONSerializer, which supplies the basic behavior for dealing with JSON payloads. In particular, you will want to override the extractHasMany hook:

    // elsewhere in your file
    function singularize(key) {
      // remove the trailing `s`. You might want to store a hash of
      // plural->singular if you deal with names that don't follow
      // this pattern
      return key.substr(0, key.length - 1);
    }
    
    DS.JSONSerializer.extend({
      extractHasMany: function(type, hash, key) {
        return hash[key][singularize(key)].id;
      }
    })
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I currently have an API script that returns JSON. It has worked up until
I have a REST API that returns json responses. Sometimes (and what seems to
I have a REST-ish API that returns JSON. One of the output fields is
I have made an api that returns an object as json data. I Am
I have a javascript application, that calls an api, and the api returns json.
I have an API that returns a promise from a deferred object. The problem
I have an Jersey API that returns Odata standard responses and consumes the same.
I have an API call that returns a byte array. I currently stream the
Is there a twitter API that returns mood? I have seen some websites that
I have the win32 API CommandLineToArgvW which returns a LPWSTR* and warns me that

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.