Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9160955
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T13:51:33+00:00 2026-06-17T13:51:33+00:00

I want to display some json beautified from an api in a view for

  • 0

I want to display some json “beautified” from an api in a view for debug purposes. For example, instead of displaying:

{"observations"=>{"realtime_start"=>"1776-07-04", "realtime_end"=>"9999-12-31", "observation_start"=>"1776-07-04", "observation_end"=>"9999-12-31", "units"=>"lin", "output_type"=>"1", "file_type"=>"xml", "order_by"=>"observation_date", "sort_order"=>"desc", "count"=>"2541", "offset"=>"0", "limit"=>"10", "observation"=>[{"realtime_start"=>"2013-01-10", "realtime_end"=>"9999-12-31", "date"=>"2012-12-01", "value"=>"1458.750"}, {"realtime_start"=>"2012-12-13", "realtime_end"=>"2012-12-19", "date"=>"2012-11-01", "value"=>"1435.307"}, {"realtime_start"=>"2012-12-20", "realtime_end"=>"2013-01-09", "date"=>"2012-11-01", "value"=>"1435.304"}, {"realtime_start"=>"2013-01-10", "realtime_end"=>"9999-12-31", "date"=>"2012-11-01", "value"=>"1435.303"}, {"realtime_start"=>"2012-11-01", "realtime_end"=>"2012-11-07", "date"=>"2012-10-01", "value"=>"1418.277"}, {"realtime_start"=>"2012-11-08", "realtime_end"=>"2012-11-14", "date"=>"2012-10-01", "value"=>"1418.286"}, {"realtime_start"=>"2012-11-15", "realtime_end"=>"2012-11-22", "date"=>"2012-10-01", "value"=>"1418.285"}, {"realtime_start"=>"2012-11-23", "realtime_end"=>"2012-11-28", "date"=>"2012-10-01", "value"=>"1418.284"}, {"realtime_start"=>"2012-11-29", "realtime_end"=>"9999-12-31", "date"=>"2012-10-01", "value"=>"1418.274"}, {"realtime_start"=>"2012-10-04", "realtime_end"=>"2012-10-10", "date"=>"2012-09-01", "value"=>"1409.636"}]}}

…I want to display:

{
"observations": {
    "realtime_start": "1776-07-04",
    "realtime_end": "9999-12-31",
    "observation_start": "1776-07-04",
    "observation_end": "9999-12-31",
    "units": "lin",
    "output_type": "1",
    "file_type": "xml",
    "order_by": "observation_date",
    "sort_order": "desc",
    "count": "2541",
    "offset": "0",
    "limit": "10",
    "observation": [{
        "realtime_start": "2013-01-10",
        "realtime_end": "9999-12-31",
        "date": "2012-12-01",
        "value": "1458.750"
    }, {
        "realtime_start": "2012-12-13",
        "realtime_end": "2012-12-19",
        "date": "2012-11-01",
        "value": "1435.307"
    }, {
        "realtime_start": "2012-12-20",
        "realtime_end": "2013-01-09",
        "date": "2012-11-01",
        "value": "1435.304"
    }, {
        "realtime_start": "2013-01-10",
        "realtime_end": "9999-12-31",
        "date": "2012-11-01",
        "value": "1435.303"
    }, {
        "realtime_start": "2012-11-01",
        "realtime_end": "2012-11-07",
        "date": "2012-10-01",
        "value": "1418.277"
    }, {
        "realtime_start": "2012-11-08",
        "realtime_end": "2012-11-14",
        "date": "2012-10-01",
        "value": "1418.286"
    }, {
        "realtime_start": "2012-11-15",
        "realtime_end": "2012-11-22",
        "date": "2012-10-01",
        "value": "1418.285"
    }, {
        "realtime_start": "2012-11-23",
        "realtime_end": "2012-11-28",
        "date": "2012-10-01",
        "value": "1418.284"
    }, {
        "realtime_start": "2012-11-29",
        "realtime_end": "9999-12-31",
        "date": "2012-10-01",
        "value": "1418.274"
    }, {
        "realtime_start": "2012-10-04",
        "realtime_end": "2012-10-10",
        "date": "2012-09-01",
        "value": "1409.636"
    }]
}

}

When I assign a variable @beautifiedJson = JSON.pretty_generate(parseHolder), with parseHolder being the json object and then place @beautifiedJson in my view via:

    <%= @beautifiedJson %>

…the view isn’t beautified. When I view the page source the json is formatted (proper indent and lines), however, the necessary html formatting for this to show up correctly in the view is not in place.

My question is whether I’m utilizing the rails JSON method correctly or do I need another method to accomplish the formatting?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-17T13:51:34+00:00Added an answer on June 17, 2026 at 1:51 pm

    Use:

    <pre>
        <%= @beautifiedJson %>
    </pre>
    

    If you look at the page source generated by your original code, you’ll see that it had been beautified but the browser was ignoring the newlines and tabs that the JSON.pretty_generate(parseHolder) was adding.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

1)I have a json file which I want to display in view. { contents:
I am trying to display the text from json in a list view. I
I want to display some text from server, but till then I want to
I want to display a text box with some JSON in its data attribute.
When I get some json data I want to display them in the page
I have some json data given below and I want to display it in
So I'm trying to display via a template some data from a JSON request.
I have some JSON data given below and I want to display it in
I want to display some div's in a wrap. The div have same class
I want to display some kind of animation when my datagrid is updating. Does

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.