Ruby to JSON Converter
Paste Ruby classes, hashes, or objects. Get clean JSON back.
What this tool does
If you have a Ruby class with a bunch of attributes and you need a JSON payload for a test, an API call, or a fixture, hand-rolling the hash by hand is a chore. Paste the Ruby here and you get back valid JSON with every field preserved. Whether it is one Order class, a nested Customer with addresses, or a whole file of model definitions from Rails, the output matches what you would get from to_json at runtime.
The converter understands how Ruby actually serializes. The json stdlib turns :symbol keys into strings (because JSON only has string keys), nil becomes null, and Time / Date come out as ISO-8601 strings. Hashes with symbol keys and string keys are both normalised, and arrays of mixed types stay intact. Nested instances — an Address inside an Order — are expanded into nested JSON objects, not stringified. You can read the details on ruby-doc.org.
Paste a full file from a gem or your Rails app and every top-level class comes out as its own JSON entry, with initialize-set instance variables pulled into the output. attr_accessor, attr_reader, and plain @ivars are all picked up. If the parser sees a Struct or an OpenStruct, it treats the members the same way. Methods are skipped — only data makes it into the JSON.
How to use it
Three steps. Works the same whether you paste a few lines or a whole models/ folder.
Paste your Ruby (or try the sample)
Drop your Ruby into the left editor as-is. A class definition, a hash literal, multiple classes, or a .new instance — all fine. Click Load Sample if you want to see a realistic example first.
You do not need to trim the code — keep the Ruby syntax, require lines, and comments as they are. The parser ignores what is not data. For edge cases, the JSON stdlib docs are a good read.
Hit Convert
Click the green Convert button. The tool reads the Ruby, preserves every class and attribute, and produces the JSON in one pass. You will see a short loading indicator while it runs.
Copy the JSON
The right panel fills with indented, spec-compliant JSON. Copy it into a Postman request, a test fixture, a Rails seeds file, or your API docs.
When this actually comes in handy
Test fixtures for RSpec
You have an Order model with 20 attributes and need JSON to stub an external service. Paste the class, get the payload, drop it into your spec.
Seeding a Rails app
Turn a bunch of <code>Product.new(...)</code> lines into a JSON seed file for db/seeds or a staging data loader — no hand-typing.
Docs that match your models
Generate JSON examples for a README or API reference straight from your Ruby classes so the docs never drift from the code.
Debugging serialization issues
When <code>to_json</code> is behaving oddly, paste the Ruby here to see the expected JSON shape and compare it against what your app is actually sending.
Common questions
Can I paste multiple classes at once?
Yes. Paste a whole file. Each top-level class comes out as its own JSON entry, with nested classes expanded into nested objects. Methods are ignored — only instance variables and their values end up in the output.
How are symbols and string keys handled?
JSON only has string keys, so :name becomes "name" — same behaviour as the json stdlib. If you have a hash that mixes symbol and string keys, both are normalised to strings in the output.
What about Time, Date, and BigDecimal?
Time and DateTime come out as ISO-8601 strings. Date is an ISO date string. BigDecimal becomes a JSON number. nil is null. Ranges and regexes are stringified — the rest of the standard types map the way Ruby's default to_json does them.
Does it handle Struct and OpenStruct?
Yes. A Struct with members :name, :price is serialized as a JSON object with those keys. Same for OpenStruct — the dynamic attributes are picked up and emitted.
Is my code stored?
Your Ruby is sent to the backend for conversion and is not persisted — we do not log the payload. As always with online tools, if the code is genuinely sensitive, eyeball it first.
What if the code has methods or blocks?
Methods and blocks are skipped — they are not data. Only the class name, instance variables from initialize, and literal values make it into the JSON, so the rest of your model still comes through cleanly.
Other tools you may need
Ruby to JSON is one piece. These pair well with it: