Developer Tools
JSON to Ruby Hash Converter
Convert JSON to a Ruby hash in your browser. Symbol or string keys, single or double quotes, two-space indent, frozen_string_literal, and trailing comma.
Output options
Live preview updates with every change. Parsing and emission run in your browser; the JSON you paste is not uploaded.
Key style
Smart symbols use the modern name: shorthand where the key is a valid Ruby identifier, and fall back to :"weird-key" => ... otherwise. String keys emit the literal Ruby translation that matches JSON.parse output.
String quotes
Double quotes encode newlines, tabs, and other control characters as \n, \t so the string fits on one line and survives copy-paste. Single quotes keep the literal characters and never interpolate.
Indent
The Ruby community style guide (rubocop default) uses two-space indents. Choose four if your project enforces a wider indent.
Used when "Assign to variable" is on. Invalid characters are replaced with underscores, and Ruby reserved words are prefixed with _.
Mapping reference
- JSON object becomes a Ruby hash. Insertion order is preserved (Ruby 1.9+ guarantees ordered hashes).
- JSON array becomes a Ruby array. Elements are emitted in the same order as the input.
- true, false, null map to true, false, and nil.
- Numbers keep their literal form. Ruby distinguishes integers from floats; the emitted number always parses back to the value JavaScript decoded.
- Strings are escaped for the selected quote style. Double quotes also escape #{ so values like "#{user.name}" stay literal instead of triggering interpolation.
- Privacy: every step runs in your browser. The JSON you paste is not uploaded.
How to use
- Paste a JSON value into the input on the left, or click Load sample JSON to see a worked example.
- Read the generated Ruby on the right. JSON objects become Ruby hashes and arrays stay as arrays, with insertion order preserved.
- Pick a key style: Smart symbols uses the modern name: shorthand where the key is a valid identifier, Always symbol forces symbols everywhere, and String keys matches what JSON.parse would produce without symbolize_keys.
- Choose a quote style. Double quotes encode \n, \t, and other control characters; single quotes keep the literal characters and never interpolate.
- Toggle Assign to variable to wrap the hash in a name = ... assignment, or Add frozen_string_literal to prepend the magic comment, or Append .freeze for per-string freezing.
- Click Copy Ruby to put the output on your clipboard, ready to paste into a .rb file, irb, or a Rails console.
About this tool
JSON to Ruby Hash Converter turns any JSON value into an idiomatic Ruby hash literal entirely in your browser. Paste an API response, a config blob, a fixture, or any copied object, and the tool parses it with the browser's native JSON parser, walks the resulting tree, and emits Ruby code you can drop straight into a .rb file, an irb session, an RSpec fixture, or a Rails initializer. The key style is configurable to match the way real Ruby code is written. Smart symbols use the modern shorthand form (name: value), which is the Ruby community default since 1.9 and matches what rubocop expects, and falls back to the quoted-symbol-with-rocket form for keys that are not valid Ruby identifiers (hyphens, leading digits, reserved words, or special characters). Always symbol forces every key to be a Ruby symbol, switching between shorthand and the rocket form per key. String keys emit the literal Ruby translation that matches what JSON.parse produces without symbolize_keys, which is the right shape for parsing untrusted JSON or round-tripping with the standard library. String values are escaped with the correct rules for the quote style you pick: single quotes only need to escape backslashes and the quote itself, while double quotes also escape the interpolation sigil #{} so values like "#{user.name}" stay literal instead of triggering interpolation, plus newlines, tabs, and other control characters become their familiar escape sequences. JSON objects become Ruby hashes with insertion order preserved (Ruby 1.9+ guarantees ordered hashes). JSON arrays become Ruby arrays. Booleans, null, and numbers map directly to true, false, nil, and the same numeric literal. Output controls cover everything Ruby projects care about: two-space rubocop indent or four-space house style, an optional variable assignment with a sanitized identifier, an optional frozen_string_literal magic comment for Ruby 3 best practice, an optional .freeze suffix on every string literal for projects that cannot add the magic comment, and an optional trailing comma after the last entry for cleaner diffs. A live key inspection panel surfaces how many keys use the shorthand form and how many fall back to the rocket form, with a short list of which keys triggered the fallback so you can rename them if you want a fully shorthand hash. Useful for porting JSON fixtures into RSpec or Minitest, dropping API examples into Rails initializers, building seed_fu or db/seeds.rb data, scaffolding YAML.load_file replacements, generating cached Ruby data from JSON snapshots, or turning a third-party schema dump into editable Ruby code. Parsing and emission run locally on your device, so the JSON you paste here never leaves your browser.
Free to use. Works in your browser. No signup, no login.
Related tools
You may also like
JSON to Python Converter
Generate a Python dict, dataclasses, or Pydantic models from any JSON value.
Open tool
DeveloperJSON to PHP Array Converter
Turn any JSON value into an idiomatic PHP associative or numeric array.
Open tool
DeveloperJSON to Go Struct Converter
Generate idiomatic Go structs with json tags from any JSON value.
Open tool
DeveloperJSON Formatter
Format, minify, and validate JSON in your browser.
Open tool
DeveloperJSON Tree Viewer
Collapsible JSON tree with search, JSONPath, type icons, and copy-by-node.
Open tool
ConverterYAML to JSON Converter
Two-way YAML and JSON converter with anchors, flow, and block scalars.
Open tool