1. #1
    Ext User
    Join Date
    Aug 2009
    Posts
    18
    Vote Rating
    0
    ultramedia is on a distinguished road

      0  

    Default 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...

  2. #2

  3. #3
    Ext User
    Join Date
    Aug 2009
    Posts
    18
    Vote Rating
    0
    ultramedia is on a distinguished road

      0  

    Default


    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

  4. #4
    Sencha User
    Join Date
    Mar 2008
    Location
    Marietta, GA
    Posts
    93
    Vote Rating
    0
    jasondeegan is on a distinguished road

      0  

    Default 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.

  5. #5
    Sencha User
    Join Date
    Jan 2011
    Posts
    549
    Vote Rating
    54
    willigogs is a jewel in the rough willigogs is a jewel in the rough willigogs is a jewel in the rough

      0  

    Default


    Just use something like JSON Lint?

  6. #6
    Sencha User
    Join Date
    Mar 2008
    Location
    Marietta, GA
    Posts
    93
    Vote Rating
    0
    jasondeegan is on a distinguished road

      0  

    Default 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, J
    Don't measure excellence against others, but rather against the best implementation of yourself.