Pretty JSON of any object
puts JSON.pretty_generate(obj.as_json)
The go-to. Works for hashes, arrays, ActiveRecord rows, anything that knows `as_json`.
Quick inspect in irb / pry
jj obj
`jj` is Ruby's built-in JSON pretty-printer. Fastest one-liner when you just want a look.
ActiveRecord single row
puts user.as_json.to_json
Skips the model name wrapping that some serializers add.
ActiveRecord collection
puts User.where(active: true).map(&:as_json).to_json
Use `.map(&:as_json)` so you serialize each record, not the relation.
Nested AR with associations
puts user.as_json(include: { posts: { include: :comments } }).to_json
Pull child records inline so the diff covers the whole tree.
Hash with symbol keys
puts obj.deep_stringify_keys.to_json
Forces symbol keys to strings so the JSON parser is happy.
Raw pp output (use Normalize toggle)
pp obj
No JSON conversion. Paste it raw and let Diffy's normalizer handle the Ruby syntax.
Awesome print (plain)
ap obj, plain: true, html: false
`plain: true` strips colors; `html: false` keeps it terminal-safe.
File.write("/tmp/a.json", JSON.pretty_generate(obj.as_json))
For huge payloads. Write to disk and upload the file via drag-and-drop.
Compare two AR records at once
puts JSON.pretty_generate([before.as_json, after.as_json])
Emits an array of two. Split into left/right manually, or paste both halves separately.
API response in a Rails request spec
puts JSON.pretty_generate(JSON.parse(response.body))
Re-parse + re-serialize so symbol ordering is consistent.
Filter out noisy keys at source
puts JSON.pretty_generate(obj.as_json.except("updated_at", "created_at"))
Alternative to Diffy's ignore rules. Strip in Ruby before pasting.