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?

Pardeep Dhingra
  • 3,916
  • 7
  • 30
  • 56
Sung Kim
  • 15
  • 5
  • Please show your json and how different you are getting on your work machine – Pardeep Dhingra Jun 19 '15 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. – Sung Kim Jun 19 '15 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. – Sung Kim Jun 19 '15 at 17:21
  • 1
    Are you viewing this output in a web browser by any chance? – zetetic Jun 19 '15 at 17:22
  • Yes I am (localhost:3000/todos). – Sung Kim Jun 19 '15 at 17:24

2 Answers2

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.

fny
  • 31,255
  • 16
  • 96
  • 127
  • 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. – Sung Kim Jun 19 '15 at 17:57
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!

monkbroc
  • 808
  • 9
  • 13