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

  • Home
  • SEARCH
  • 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 6659675
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T02:03:38+00:00 2026-05-26T02:03:38+00:00

If I JSON.stringify a backbone model with nested collections/models, send it via websockets to

  • 0

If I JSON.stringify a backbone model with nested collections/models, send it via websockets to another backbone client and JSON.parse the mode model = JSON.parse(model) will the variable model work just as it did on the other client?

  • 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-05-26T02:03:39+00:00Added an answer on May 26, 2026 at 2:03 am

    No.

    Perhaps I will elaborate. When I do this:

    var o = JSON.parse(JSON.stringify(model));
    

    I end up with a simple object in o. Why? Well, first of all, JSON.parse() doesn’t know anything about non-primitive types (where Array and Object are considered primitive) and in particular, it doesn’t know what a Backbone model is so it can’t rebuild one. Furthermore, JSON.stringify will call the toJSON method on its argument (if it has one of course) and Backbone supplies a toJSON that simply returns a copy of the model’s attributes as a simple (possibly nested) object. So once you have the output from JSON.stringify(model), there is no connection at all between the string and the model, you just have a plain old serialized JavaScript object.

    If you want to move a Backbone model from one system to another, I think you’d have to track all the model type and object information yourself and then rebuild your serialized piece of the object graph by hand on the other side.

    You’d probably be better off saving the model back to its URL, sending the ID to the other Backbone client, and then reload it from the model’s URL as usual. JSON is for serializing data, not objects, interpreting the data as objects is left up to the application.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Item.find().sort([['_id','descending']]).limit(15).each(function(doc) { client.send(JSON.stringify(doc)); }); Returns this error: Error: Error: Illegal sort clause, must be
What's the fastest alternative to JSON.parse(JSON.stringify(x)) There must be a nicer/built-in way to perform
For example, this code: var a = {}; a.a = a; JSON.stringify(a); Will throw:
I'm using JSON.stringify and JSON.parse to store and retrieve objects from localStorage . However,
I downloaded the JSON2.js from https://github.com/douglascrockford/JSON-js/blob/master/json2.js and it does not have implementation for JSON2.stringify()
I know of YUI who has a JSON.stringify utility and also of JSON2 from
I am trying to use JSON.stringify() (from json2.js of json[dot]org ) to convert a
I just learned about jquery's .makeArray and I am trying to use JSON.stringify to
Here's my jquery: $.ajax({ type: 'GET', url: '/services/Service.asmx/FamilyHistory', data: JSON.stringify({ userID: 10, historyID: famid
I'm looking for a way to define and send a JSON object array. I've

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.