0

I just got a new computer at work and I have been noticing things that are different from my work computer and home computer.

One that is perplexing me at the moment is the JSON output by Rails. At home, it puts out the JSON automatically in a way that is easy read. (With color, indentation etc)

Instead, I get one lump block -_-;

[{"id":1,"title":"ratione fuga perferendis","is_completed":false,"created_at":"2015-06-19T16:48:27.947Z","updat‌​ed_at":"2015-06-19T16:48:27.947Z"}] 

Anyone know how to fix it?

5
  • Please show your json and how different you are getting on your work machine Commented Jun 19, 2015 at 17:13
  • This is the JSON block I am getting. [{"id":1,"title":"ratione fuga perferendis","is_completed":false,"created_at":"2015-06-19T16:48:27.947Z","updated_at":"2015-06-19T16:48:27.947Z"} instead of something formatted with correct spacing and indentation. I can't post an image, otherwise I would. Commented Jun 19, 2015 at 17:14
  • I might be a gem but I am sure it was a default behavior of Rails so I am trying to find out why it is not behaving this way. Commented Jun 19, 2015 at 17:21
  • 1
    Are you viewing this output in a web browser by any chance? Commented Jun 19, 2015 at 17:22
  • Yes I am (localhost:3000/todos). Commented Jun 19, 2015 at 17:24

2 Answers 2

2

That's probably your browser being nice to you. There are lots of extensions for Chrome and Firefox that will automatically format your JSON for you:

You don't really want Rails to handle the pretty printing for you since that would dramatically increase the size of your JSON responses.

Sign up to request clarification or add additional context in comments.

1 Comment

I am not sure if it was the browser being nice or not but this does allow me to see the pretty JSON without bloating Rails.
1

I suggest you use a JSON formatting browser extension like Pretty Beautiful Javascript.

This way the JSON can stay optimized for computers to consume, but will look great for you when you need to look at it. It will even have syntax highlighting!

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.