Skip to content
100% local

Ruby hash to JSON

Convert a Ruby hash literal or pp/inspect output to JSON, or back.

Input
Output

Ruby hash to JSON

Paste a Ruby hash literal, or the output of `pp`, `.inspect` or a Rails console, and this tool converts it to clean JSON. It understands both hash key styles — the classic hash rocket (`:name => 'Alice'`, `'name' => 'Alice'`) and the modern shorthand (`name: 'Alice'`), including quoted shorthand keys like `'full name': 'Alice Smith'`. Nested hashes and arrays, single- and double-quoted strings, symbols (`:active` becomes the string "active"), integers and floats with underscore thousand separators (`1_000_000`), `true`, `false`, `nil`, trailing commas, `#` comments and multi-line input are all handled, so you can paste console output exactly as it was printed.

The options control how the JSON comes out. Toggle pretty-printing with a 2-space, 4-space or tab indent, or collapse everything to one line. Symbol keys can render as plain JSON strings or keep a leading colon (`":name"`) as a reminder of where they came from. Sorting keys alphabetically makes two hashes easier to diff. A Ruby `nil` can become JSON `null` or be dropped from the output entirely, whichever your downstream tool expects. The direction switch reverses the whole thing: paste JSON and get back a Ruby hash literal, choosing shorthand or hash-rocket syntax for the generated keys.

This covers the everyday cases of debugging a Rails console session, turning a hardcoded configuration hash into JSON for a frontend or an API test, documenting what a method actually returns, or seeding a Ruby fixture from a JSON payload someone sent you. When the input isn't valid Ruby, the error names the exact line and column and what was expected there, instead of leaving you to guess which bracket is missing.

Everything runs locally in your browser — the hash or JSON you paste, which can include real data from a running application, is never uploaded anywhere. Copy the result, download it as a .json file, or send it straight into another tool such as the JSON formatter to keep working.

FAQ

Which Ruby hash syntax does this tool understand?
Both hash rocket style (`:key => value`, `'key' => value`) and shorthand symbol style (`key: value`, including quoted keys like `'full name': value`), plus nested hashes and arrays, single- and double-quoted strings, symbols, numbers with underscore separators, `true`/`false`/`nil`, trailing commas, `#` comments and multi-line input.
What happens to Ruby symbols?
A symbol value like `:active` becomes the JSON string "active". A symbol used as a hash key (whether written `:name => ...` or as shorthand `name: ...`) becomes a plain JSON string key by default, or keeps a leading colon (`":name"`) if you choose that option.
How does the tool handle Ruby's nil?
Choose whether `nil` converts to JSON `null` (the entry stays, with a null value) or is omitted entirely, so the key disappears from the output.
Can I convert the other way, from JSON back into a Ruby hash?
Yes. Switch the direction to "JSON → Ruby hash" and pick whether the generated keys use hash-rocket (`:key => value`) or shorthand (`key: value`) syntax.
Is my Ruby code or JSON uploaded anywhere?
No. Parsing and conversion run entirely in your browser using JavaScript — nothing you paste is sent to a server.