-
6 Oct 2009 6:36 PM #1
display formatted JSON?
display formatted JSON?
Hey everyone,
Bit new to ExtJS so sorry if this is a dumb question.
I wrote a function that takes raw JSON data and reformats it so that I can plug it straight into an ExtJS tree. It's *sort* of working because the tree is displaying, but I just realized it's doesn't have all of the data from the original JSON file so something needs fixing.
I figured out how to dump my reformatted JSON data in human readable format to a panel using encode, but there are no line breaks or indenting so it's stupid hard to look through for stuff done wrong.
Has anyone written a nice function for displaying encoded JSON with line breaks and indenting or is there an even easier way of doing this that I just don't know about yet? I looked in the API for a formatting option on the 'encode' keyword but didn't see anything...
-
6 Oct 2009 9:15 PM #2Search the forum: http://www.google.com/coop/cse?cx=01...%3Az7of1ufqccu
Read the docs too: http://extjs.com/deploy/dev/docs/
Scope: http://extjs.com/forum/showthread.ph...642#post257642
-
6 Oct 2009 10:41 PM #3
Well, that would be pretty darn witty if you hadn't completely misunderstood what I was asking. But that's ok, I've already written the function that accepts a JSON object, encodes it then renders it to HTML with line breaks and indenting so that you can manually eyeball through it looking for problems (sort of like debug_var does with arrays in PHP).
Actually, I should probably thank you. I *was* going to post the code in case it was something that somebody else needed down the track, but you've helped me realize what a silly idea it was all along, and how much embarressment I can save myself by not posting it.
*Phew* thanks animal
-
21 Feb 2013 6:57 AM #4
He's a ..
He's a ..
Please help the community by posting your formatted JSON function. Don't let one D-bag ruin it for everyone.
Don't measure excellence against others, but rather against the best implementation of yourself.
-
21 Feb 2013 8:26 AM #5
-
21 Feb 2013 8:28 AM #6
That works as a manual step
That works as a manual step
It's for a dev environment, I want to print a "pretty" JSON to the screen...I used this:
<script>
widgetObject = <?php echo json_encode( $widget[0] ) ?>;
widgetDetail = JSON.stringify( widgetObject, null, 4 );
</script>
and stuck widgetDetail in <pre> tags.
Thanks, JDon't measure excellence against others, but rather against the best implementation of yourself.


Reply With Quote