Why are some Class properties hidden from dojo.toJson?

Posted on 2011-10-14
Last Modified: 2012-06-27
I have a class I've created using dojo.declare.  This class has a number of properties with default values.  I also have a method in the class that takes the object and puts it into a json string.  

But a funny thing is happening.  When I set a breakpoint just before the call to dojo.toJson all of the properties including those values set in the declare are correctly displayed in the debugger, but only those values that are not defaults are included in the json string.

For example,  if I have a class with a property of P1 and P2 and P2 has a default value (defined in the class--declare), and P1 is set manually only P1 is included in the json string returned from dojo.toJson().  See below:

var m = new myclass();
m.P1 = "Test";

dojo.declare("myclass", null, {
P1 : "value1",
P2 : "value2",
    constructor: function (args) {
        dojo.mixin(this, args);
   createjson: function(args) {
    var cJson = dojo.toJson(this);   //cJson string does not include P2


Open in new window

Question by:marketware
    1 Comment

    Accepted Solution

    I don't know if there is an answer out there for this question.  My workaround is to manually populate the properties instead of relying on the default values.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Preface In the first article: A Better Website Login System ( I introduced the EE Collaborative Login System and its intended purpose. In this article I will discuss some of the design consideratio…
    Preface This is the third article about the EE Collaborative Login Project. A Better Website Login System ( introduces the Login System and shows how to implement a login page. The EE Collaborative Logi…
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
    In this fourth video of the Xpdf series, we discuss and demonstrate the PDFinfo utility, which retrieves the contents of a PDF's Info Dictionary, as well as some other information, including the page count. We show how to isolate the page count in a…

    737 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    21 Experts available now in Live!

    Get 1:1 Help Now