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 8481349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 10, 20262026-06-10T19:32:22+00:00 2026-06-10T19:32:22+00:00

Can someone explain how JSON.stringify() magically ONLY stringifies JSON as fetched by URL and

  • 0

Can someone explain how JSON.stringify() magically ONLY stringifies JSON as fetched by URL and does NOT bother with other backbone-specific parts of the full collection object?

I am curious about underlying implementation and/or design patterns that explain this very impressive capability. I had to use json2.js to get stringify functionality, so I don’t think backbone is overriding or decorating stringify.

I discovered that if I pass a collection directly to JS OBJECT code, the code “sees” model keys and other backbone-specific parts of a collection object, whereas if I perform JSON.stringify THEN jquery.parseJSON on that stringified object, my code “sees” only the JSON as returned by URL.

Code:

enter code here

$(function () {
    var Person = Backbone.Model.extend({
        initialize: function () {
            // alert("Model Init");
        }
    }),
    PersonList = Backbone.Collection.extend({
        model: Person,
        url: '/Tfount_Email/Email/SOAInbox',
        initialize: function () {
            // alert("Collections Init");
        }
    }),
    personlist = new PersonList();

    personlist.fetch({
        error: function () {
            alert("Error fetching data");
        },
        success: function () {
            // alert("no error");
        }
    }).complete(function () {

    // first call to makeTable w collection obj, we see MORE than just the JSON returned by URL
        makeTable(personlist);      

    // stringify then parse, we see only JSON returned by URL
        jsonString = JSON.stringify(personlist);
        var plistJSON = jQuery.parseJSON(jsonString);
        makeTable(plistJSON);
    });
});

function makeTable(obj) {

    var type = typeof obj
    if (type == "object") {
        for (var key in obj) {
            alert("key: " + key)
            makeTable(obj[key])
        }
    } else {
        alert(obj)
    }

}
  • 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-10T19:32:23+00:00Added an answer on June 10, 2026 at 7:32 pm

    This is the intended and by-design behavior of JSON.Stringify. From Douglas Crockford’s JSON2.js file:

    When an object value is found, if the object contains a toJSON method, its toJSON method will be called and the result will be stringified.

    https://github.com/douglascrockford/JSON-js/blob/master/json2.js#L38-39

    When you call JSON.stringify on a Backbone.Collection, it calls that collection’s toJSON method, as described by this comment.

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

Sidebar

Related Questions

Can someone explain how to use JSON-RPC.net in my application for windows phone. When
Can someone explain why it's best use is for prototyping? Should it not be
Can someone explain what is json method and it use in .net
Can someone explain the following behavior? Specifically, why does the function return a different
can someone explain why this jquery selector is not working, I've worked around the
Can someone pleas explain to me why json which contains a string with double
I am not too familiar with javascript. Can someone please explain this construct to
Can someone explain why this code works: $('#FonykerUsernameRegister').blur(function(){ if($(this).val().length > 2) { $.ajax({ url:
can someone explain me how to use JSON? I know it has something in
I am new to JSON and JavaScript objects. Can someone please explain the differences

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.