JavaScript data formatting/pretty printer

Posted by Dan on Stack Overflow See other posts from Stack Overflow or by Dan
Published on 2008-09-24T22:46:53Z Indexed on 2010/06/06 16:52 UTC
Read the original article Hit count: 306

Filed under:
|
|

I'm trying to find a way to 'pretty print' a JavaScript data structure in a human-readable form for debugging.

I have a rather big and complicated data structure being stored in JS and I need to write some code to manipulate it. In order to work out what I'm doing and where I'm going wrong, what I really need is to be able to see the data structure in its entirety, and update it whenever I make changes through the UI.

All of this stuff I can handle myself, apart from finding a nice way to dump a JavaScript data structure to a human-readable string. JSON would do, but it really needs to be nicely formatted and indented. I'd usually use Firebug's excellent DOM dumping stuff for this, but I really need to be able to see the entire structure at once, which doesn't seem to be possible in Firebug.

Any suggestions welcome, thanks in advance.

© Stack Overflow or respective owner

Related posts about JavaScript

Related posts about debugging