Ruby hash to JSON
Convert a Ruby hash literal or pp/inspect output to JSON, or back.
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.