Paste Perl on the left and click "Convert" — we will turn it into JSONPaste Perl code

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

Three steps. Works the same whether you paste a small hash ref or a full config dump.

1

Paste your Perl (or try the sample)

Drop your Perl into the left editor as-is. A hash ref, an array ref, multiple declarations, or a blessed object — all fine. Click Load Sample if you want to see a realistic example.

Leave the reference syntax alone — \%hash, \@array, {...}, [...]. The parser understands them all.

2

Hit Convert

Click the green Convert button. The tool walks the Perl structure, resolves references, and builds the JSON in one pass.

3

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 <code>undef</code>, <code>JSON::true</code>, <code>JSON::false</code>?

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 <code>Data::Dumper</code> 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?

Your code goes to the backend for conversion and is not persisted — we do not log the payload. If the hash ref contains real credentials, swap them out before pasting.

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

Perl to JSON pairs well with the rest of the toolbox: