Pretty-print JSON in Ruby
When receiving a JSON payload it can, of course, be useful to see it in a more readable way. Turns out there is a built in utility in Ruby that can help with this.
Utilizing the Kernal#j
method:
foo = {name: "Matt", company: "Hashrocket"}
=> j foo
{"name": "Matt", "company": "Hashrocket"}
Utilizing the Kernal#jj
method:
foo = {name: "Matt", company: "Hashrocket"}
=> jj foo
{
"name": "Matt",
"company": "Hashrocket"
}
Tweet