JSON to Ruby hash converter

Useful for Rails seeds, RSpec fixtures and config when your data starts as JSON.

Loading the tool…

Processing and privacy: The result is calculated inside your browser and your data is not sent to any server.

How to use it

  1. Enter json and key style.
  2. The result appears straight away and updates as you edit.
  3. Copy the result, or copy a link that keeps the same values to share it.

How it is calculated

Objects become hashes, arrays become arrays and null becomes nil. In symbol mode a key is written name: or "first-name": when it is not a plain name. Strings use double quotes with \, " and #{ escaped so no interpolation happens.

Example

Inputs: Key style = Strings "key" =>. Result: Ruby hash: { "name" => "Ali", "age" => 30, "active" => true, "tags" => [ "admin", "editor" ], "address" => { "city" => "Riyadh", "zip" => nil } }; Values converted: 7.

{
  "name": "Ali",
  "age": 30,
  "active": true,
  "tags": ["admin", "editor"],
  "address": {
    "city": "Riyadh",
    "zip": null
  }
}
{
  "name" => "Ali",
  "age" => 30,
  "active" => true,
  "tags" => [
    "admin",
    "editor"
  ],
  "address" => {
    "city" => "Riyadh",
    "zip" => nil
  }
}

Limits and caveats

  • Symbol mode matches JSON.parse with symbolize_names: true; string mode matches plain JSON.parse.
  • Strings holding an unpaired UTF-16 surrogate are not valid in Ruby and give an error.

Questions about this tool

When should I pick symbol keys?

When the code reads values as hash[:name], as most Rails code does. Pick strings if you read hash["name"].

Why does \#{ appear in some strings?

Inside a double-quoted Ruby string #{ starts interpolation, and the escape keeps it as plain text.

Does the output work in every Ruby version?

Quoted symbol keys like "text": need Ruby 2.2 or later; the rest works in older versions too.