backbone-nestedjson

A toJSON replacement that handles nested objects

npm install backbone-nestedjson
6 downloads in the last week
11 downloads in the last month

build status

Backbone-NestedJSON

A simple replacement for #toJSON that can handle nested Backbone models.

Usage

npm install -S backbone-nestedjson

var Backbone = require('backbone');
var toJSON = require('backboned-nestedjson');
var TestModel = Backbone.Model.extend();
TestModel.prototype.toJSON = toJSON;
var tm = new TestModel();

tm.set({
  foo: 'bar',
  boo: ['a','b'],
  baz: new TestModel({back: 'front'}),
  test: {
    hello: 'goodbye'
  }
});

tm.toJSON()
{
  foo: 'bar',
  boo: ['a','b'],
  baz: {
    back: 'front'
  },
  test: {
    hello: 'goodbye'
  }
};
npm loves you