1

Possible Duplicate:
JavaScript data formatting/pretty printer

Would like to to translate a javascript object into a string so that I can display in the browser window.

So an object that looks like this:

{
   a:1,
   b:2
}

Would display in the browser much the same way. The string might look something like this:

"{<br/>
&nbsp;&nbsp;&nbsp a:1, <br/>
&nbsp;&nbsp;&nbsp b:2  <br/>
}"

Is there any readily available code that can do this? Or perhaps another slick solution that doesn't involves me writing a function to process all the data myself?

Thanks!

Community
  • 1
  • 1
Chris Dutrow
  • 48,402
  • 65
  • 188
  • 258
  • 1
    http://stackoverflow.com/questions/130404/javascript-data-formatting-pretty-printer – Stephen Watkins Feb 16 '12 at 05:20
  • 1
    @Steve - Wow, how the heck did you find that question? – Chris Dutrow Feb 16 '12 at 05:21
  • 1
    I searched Google for JavaScript pretty printer, lol. – Stephen Watkins Feb 16 '12 at 05:23
  • @Steve - Ohhhh, haha, I didn't realize "pretty print" was a known term. – Chris Dutrow Feb 16 '12 at 05:26
  • Given that you're talking about debugging, have you tried the debugging console provided (either by default or as an add-on) by all modern browsers? Have a look into `console.dir(yourobject)`. – nnnnnn Feb 16 '12 at 05:30
  • @nnnnnn - I use Firebug and sometimes Chrome's developer tools. I'm not familiar with "console.dir(object)" though. The reason I'm trying to do this is because I need to be able to look back and see objects that are associated with events that will have already come and gone in the past. – Chris Dutrow Feb 16 '12 at 15:08
  • @DutrowLLC Do *not* make edits like the one that you did. Instead, flag for moderator attention and indicate what question this is a duplicate of. – casperOne Mar 13 '12 at 13:59
  • @casperOne - No problem, I see you edited it as well, did you fix it? – Chris Dutrow Mar 13 '12 at 15:39
  • @DutrowLLC The banner that is at the top is auto-inserted when closed as a duplicate. It's fixed now, but please refrain from such edits in the future. – casperOne Mar 13 '12 at 15:40
  • @casperOne - Yeah man, no problem. – Chris Dutrow Mar 13 '12 at 15:47

0 Answers0