Why don't you just use console.dir(obj) ? Or use console.log(obj) and then click on exit / expand it?
Also, when I try to execute the following code:
var obj = {}; obj.players = {}; obj.players[0] = {color: "green"}; obj.players[1] = {color: "blue"}; obj.world = "xyz"; console.log(JSON.stringify(obj));
I always (Firefox, Chrome, Opera) get this as output:
{"players":{"0":{"color":"green"},"1":{"color":"blue"}},"world":"xyz"}
Also, it looks like your players object is actually an array. Therefore, you are better off creating it as such.
Update: I just noticed that you added a link to the JSFIDDLE demo, which empties the players object immediately after registering it. As far as I know, all web development tools use some kind of asynchronous display, which leads to an empty players object when using console.log(obj) or console.dir(obj) . Thus, Firebug gives the best results by displaying the object correctly using console.dir(obj) .
Sebastian zartner
source share