Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Pretty printing a JSON string in HTML

I have a string like { "a": "1", "b": "2", "c": "3", "asefw": "Chintan" } and I need to properly indent it to print it out in html.

Right now, I'm using a combination of google-code-prettify (for syntax highlighting), and ruby's JSON object to print it out, but the indentation is slightly off: enter image description here

Here's the relevant code from my Rails view:

.container
  .row.demo-samples
    .span9{:style => "\n-moz-border-radius: 8px 8px 6px 6px;\nborder-radius: 8px 8px 6px 6px;"}
      [email protected] do |content|
        %pre
          %code.prettyprint
            =JSON.pretty_generate(JSON[content.content])

It looks like everything but the first row is indented too much. Any idea how to fix this?

like image 223
chintanparikh Avatar asked Jun 10 '26 01:06

chintanparikh


1 Answers

This FAQ entry might help....

http://haml.info/docs/yardoc/file.FAQ.html#q-preserve

like image 66
Philip Hallstrom Avatar answered Jun 11 '26 18:06

Philip Hallstrom