How to Convert Ruby Hash to JSON
Learn how to convert Ruby hash syntax to valid JSON format.
Ruby hashes are a core data structure in Ruby and Rails applications. When debugging, you often see output like:
{:id=>1, :name=>"Rohith", :email=>"rohith@example.com", :active=>true}
This is valid Ruby syntax, but it's not valid JSON. The differences:
- Ruby uses `=>` (hash rocket) syntax instead of `:`
- Ruby symbols (`:id`) aren't valid JSON keys
- Ruby `true/false/nil` vs JSON `true/false/null`
**Converting manually is tedious.** Use DevConvert to paste and convert instantly.
Example
Input (Ruby Hash):
{:id=>1, :name=>"Rohith", :role=>:admin, :active=>true, :score=>9.5}
Output (JSON):
{
"id": 1,
"name": "Rohith",
"role": "admin",
"active": true,
"score": 9.5
}
DevConvert auto-detects Ruby hash syntax and converts it instantly with 98% confidence.