My favorites | Sign in
Project Home Wiki Issues
New issue   Search
  Advanced search   Search tips   Subscriptions
Issue 2560: Add JSON String Copy to DOM Panel
5 people starred this issue and may be notified of changes. Back to list
Reported by, Dec 7, 2009
This patch adds capability to save a JavaScript object in the DOM panel to
a JSON string. This patch supports cyclic data structures in the JavaScript
object for more robust debugging support.

The steps to utilize feature
1. Inspect any element in the DOM panel
2. Right click on the top navigation bar in DOM panel to get option for the
entire object
3. Right click on any individual object in the DOM panel to get option

The JSON string for the object will be copied to the clipboard

A sample test case has been attached for cyclic data structures

Dec 7, 2009
This patch was created from the firebug 1.6 branch
Dec 7, 2009
Project Member #2
Sorry but the patch file is way off. 129kb? Please look at the patch file.

It would be very helpful if you can explain the usage with smaller steps and in terms
of the UI components. I don't know what the first step means.

Also putting the instructions directly in the web page (esp. with little screen
shots) makes the use much clearer.
Labels: Type-Enhancement
Dec 7, 2009
Sorry, I'm not sure why my patch generation did not. My fault for not checking before
I uploaded. I'm attaching the fixed patch with a more verbose test case. 

To clarify the steps to use the feature:

Go to any website that will load objects into the Console, such as
Now, go to the Console tab and choose any element and right click to select Inspect
in DOM Tab.

Next, right on the top where it says: XPCNativeW...ttpRequest and a new option will
appear to Copy as JSON. This will copy the JSON string for the entire object in the
panel into the clipboard.

Likewise, all valid objects in the DOM Panel will also have this option.

Hope this clears up any confusion.
95.7 KB   Download
Dec 7, 2009
Project Member #4
Can you give a short summary of the changes made to json2.js? This code causes two
issues for us 1) We need to investigate the compatibility of the source licenses
(probably ok), and 2) maintainability, since we would want to track changes to
json2.js. For that later purpose, an idea of the changes would be helpful. 
Status: Triaged
Labels: dom contribution 1.5
Dec 7, 2009
json2.js provides an implementation for both JSON.stringify and JSON.parse; we only
took out the relevant code that was necessary to create JSON.stringify. The way that
the code is set up in JavaScript is foreign to us, written in a way such that it is
self contained and contains state variables.

What we did was we pulled out three specific functions: stringify, quote, and str.
These are used in our implementation. The state variables that each of these
functions referenced were passed across the functions as parameters. 

In order to handle cycle detection we added an array to track repeated values down
each branch of an object in the 'str' function. 

After looking at the patch, it looks like this is an old revision of the patch, so
I've uploaded the latest version which more efficiently does the cycle detection
check as per comments from Antonin as well as removing all tabs from the code.

Let me know if this isn't enough detail
5.8 KB   View   Download
Dec 8, 2009
Project Member #6
(No comment was entered for this change.)
Cc: odvarko
Dec 8, 2009
Project Member #7
The key question for me is whether we can use EcmaScript/Firefox JSON support:
Dec 8, 2009
good idea, let's drop that cycle detection altogether and use native JSON support

try ... catch and just report there was a cycle/problem encoding JSON
Dec 8, 2009
Project Member #9
Mike any comment on the cycle detection bit? Did you run into this issue?
Cc: collins.mike
Dec 8, 2009
Project Member #10
I ran into some issues with Crossfire using native JSON in Firefox, when you pass it
things with lots of circular references, like Window or Document objects, you
(eventually) get 'too much recursion' errors.  I work around this in Crossfire by
replacing objects with a Crossfire 'handle' object before calling toJSON, but I'm not
sure if that's an option in this case.
Dec 8, 2009
oh, don't tell me there not effective detection of cyclic data structures in native JSON :(
Dec 8, 2009
We also ran into issues with Window and Document objects, but we don't believe it was
due to recursion, but the inability to access certain objects. If you try to copy a
JSON string for one of these objects, we alert the user with the exception, which we
felt was the correct course of action. 

And we did not find an effective method of cycle detection in native JSON which
caused us to use this alternative method.
Dec 8, 2009
Project Member #13
Ok thanks.

We can take this code for 1.6, but I want to get bugs filed on bugzilla for the two
problems found with native JSON support.
Labels: blocks1.5
Dec 16, 2009
Project Member #14
Might be related:
Labels: bugzilla
Dec 18, 2009
Project Member #15
Honza, I checked and the Firefox team thinks native json should support anything
json2.js supports. They of course want a test case in bugzilla. Can you volunteer?
Dec 18, 2009
Project Member #16
(No comment was entered for this change.)
Labels: -blocks1.5 blocks1.6
Dec 21, 2009
Project Member #17
I have reported following bug:

Jun 29, 2010
Project Member #18
(No comment was entered for this change.)
Owner: odvarko
Cc: -odvarko
Aug 13, 2010
Project Member #19
Changing to 1.7 blocker.
Labels: -blocks1.6 blocks1.7
Feb 11, 2011
Project Member #20 sroussey
While this is interesting, JSON does not (by its nature) support arbitrary objects. I don't think this should go into Firebug, nor should it block the release of 1.7. 

The one way I see that it *could* go in, is if when deciding to show the "Copy to JSON" we first detect if it could be JSON, and if not then *show*, but *disable* the menu item. This way we also just use the built in JSON functions, and never give the user an alert popup. We could potentially give the disabled menu item a tooltip saying that the object has cycles and will not create a proper JSON object.

An extension to Firebug could override that behavior and do things like adding unique id properties to every object that is in a cycle and having references to those ids when the a previously seen object is encountered. This is the sort of thing that print_r in PHP does.

PS: I am assuming that the JSON.stringify in JS is not so dumb to actually run into and throw real recursion errors, but know that it would when seeing a cycle, and thus won't be too slow.
Feb 22, 2011
Project Member #21
Seems like this issue has some challenges. I also do not understand the use case enough: partial copy DOM object to JSON and then what can we do?  We might have more luck with both the cost and benefit side in the newsgroup.  
Labels: -blocks1.7
Oct 7, 2011
Just changed standard label for platform issues.
Labels: -bugzilla platform
Sign in to add a comment

Powered by Google Project Hosting