0

When fetching Backbone.js Collections from an API, Backbone expects a JSON array:

[
    {
        id: 1,
        name: "whatever"
    },
    {
        id: 2,
        name: "another"
    }
]

I guess this is a security risk, see: JSON security best practices?

I would like to make Backbone understand the following format:

{
    things: [
        {
            id: 1,
            name: "whatever"
        },
        {
            id: 2,
            name: "another"
        }
    ]
}

I there an easy way of doing this?

Community
  • 1
  • 1
jgroenen
  • 1,332
  • 1
  • 8
  • 13
  • 1
    Did you try reading the [Documentation](http://backbonejs.org/#Model-parse)? – Andrew Jul 03 '13 at 15:14
  • I did, but I was also wondering if there where more people having these security concerns and if there is a "best practice" for this in Backbone. – jgroenen Jul 04 '13 at 08:23

1 Answers1

0
var Library = Backbone.Collection.extend({
  parse: function(response) { // This is called after the `fetch()` got its data
    return response.things;
  }
});

However I don't see any security threat using simple array..

Poni
  • 11,061
  • 25
  • 80
  • 121
  • http://stackoverflow.com/questions/3503102/what-are-top-level-json-arrays-and-why-are-they-a-security-risk – jgroenen Jul 04 '13 at 07:51