Sung Kim
Sung Kim

Reputation: 15

Rails 4 "Pretty" JSON output

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?

Upvotes: 0

Views: 196

Answers (2)

fny
fny

Reputation: 33625

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.

Upvotes: 2

monkbroc
monkbroc

Reputation: 838

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!

Upvotes: 1

Related Questions