Perl to JSON Converter
Paste a Perl hash ref or array ref. Get clean JSON back.
Input
Output
Paste your Perl code on the left and press Convert.
Or drop a file on this box, , or .
What this tool does
If you have ever stared at a deeply nested Perl hash ref and tried to hand-write the equivalent JSON, you know the pain: => vs :, quoted keys, escaped strings, the works. Paste the Perl here and you get back valid JSON without rewriting anything. It handles a single {...} hash ref, a chain of my $x = {...}; my $y = [...]; declarations, or something five levels deep with array refs inside hash refs inside more hash refs.
It matches what you would get from JSON::PP or Cpanel::JSON::XS with canonical => 1. Hash refs become JSON objects, array refs become arrays, undef becomes null, numbers stay numbers, strings stay strings. The Perl documentation ambiguity between "1" and 1 gets resolved the usual way, if it looks numeric, it is emitted as a JSON number.
Blessed references (the Perl version of objects) are unwrapped to their underlying hash ref, so a bless { ... }, "Order" comes out as a plain JSON object with the same keys. JSON::true, JSON::false, and JSON::null sentinel values convert to their JSON equivalents. Multiple top-level declarations end up as keys in the JSON output, keyed by the variable name.
How to use it
Whether it is a five-key hash ref or a Data::Dumper dump of a whole config, you go through three steps.
Paste your Perl (or try the sample)
Paste Perl into the left editor: my $order = {...}; hash refs, array refs, blessed objects, or several declarations in a row. Load Sample loads an order and a customer hash ref with JSON::true flags and an undef note.
Leave the reference syntax alone: \%hash, \@array, {...}, [...]. The parser understands them all.
Hit Convert
Click the green Convert button and your Perl is shipped off for conversion. The backend chases each reference, maps => pairs to keys and undef to null, and returns the JSON.
Copy the JSON
The right panel shows indented JSON, ready for an API payload, a fixture file, or a CPAN module test. Copy and move on.
When this actually comes in handy
Migrating off Storable or Data::Dumper
You have years of legacy Perl hash dumps and need to hand them off to a modern API: JSON is the lingua franca. Paste and get proper JSON without writing an encoder.
Feeding a REST endpoint from a Perl script
Your cron job builds a hash ref from a database query. Before firing it at a REST API, paste here to verify the JSON shape matches what the server expects.
Writing test fixtures
Take a hash ref straight from a Perl module test, convert to JSON, drop it into a .json fixture file for cross-language tests.
Sharing config with non-Perl devs
A Perl config file uses hash refs everywhere. Convert to JSON so the Node, Go, or Python team can read it without installing Perl.
Common questions
Does it handle blessed objects?
Yes. A blessed hash ref (e.g. bless { id => 1 }, "Order") is treated as its underlying hash ref: the class name is dropped and the keys/values come through as a plain JSON object. This matches how JSON::PP behaves with convert_blessed.
What about undef, JSON::true, JSON::false?
undef becomes JSON null. JSON::true / \1 becomes true, JSON::false / \0 becomes false. These are the standard boolean conventions from Cpanel::JSON::XS.
Can I paste Data::Dumper output?
Yes. Output from Data::Dumper (the $VAR1 = {...}; form) parses fine. The leading $VAR1 = is treated as a variable name and becomes the outer key.
How are numbers vs strings handled?
Perl is loose about the difference. The converter follows the common rule: bare numeric literals (42, 3.14) become JSON numbers, and anything quoted ("42") stays a JSON string. If you need a string that looks numeric, quote it.
Is my code stored?
It goes to the backend for the conversion and is not stored. CGI scripts and cron jobs from older Perl codebases often have database passwords inline in the hash ref, so remove those first.
What if I paste multiple hash refs?
Each top-level my $name = {...}; becomes a key in the output JSON, named after the variable. Anonymous structures get "_1", "_2", etc. Nothing is silently dropped.
Other tools you may need
Migrating Perl configs to YAML or XML, or double-checking the JSON, these are handy: