{}, [], strings, numbers, true/false, nil, symbols) and both => and key: hash syntax.
How to use
Use this formatter to clean up Ruby Hash literals (including nested hashes/arrays).
- Paste your Ruby hash into the input box.
- Choose options (Pretty/Minify, indent, quote style, key sorting, output format).
- Click Format (or Minify).
- Copy the result from the output area.
FAQ
Is this formatter safe to use with untrusted input?
Yes. It does not run Ruby or use eval; it parses a limited Ruby-literal subset in JavaScript.
What Ruby hash syntax is supported?
Common literals: hashes ({}), arrays ([]), strings, numbers, booleans, nil, symbols, and both key: and => pairs.
Can it convert hash rockets to <code>key:</code> syntax?
Yes, when the key is a simple symbol name it will output key:. Other keys keep =>.
Does it preserve comments and complex Ruby expressions?
No. Comments are ignored, and complex expressions (method calls, constants, heredocs, etc.) are not supported.
Can I sort keys for stable diffs?
Yes. Enable “Sort hash keys” to output keys in a consistent order.
Can I output JSON instead of Ruby?
Yes. Switch Output to JSON; symbols become strings and nil becomes null.
Why am I getting a parse error on valid Ruby code?
This tool intentionally supports only Ruby literal subsets. If your hash contains non-literals, simplify it (or replace values with placeholders) before formatting.