JSON to Perl Converter
Turn JSON into a Perl data structure you can use or require
JSON Input
Perl Output
What does the JSON to Perl converter do?
If you want JSON data baked into a Perl script (test fixtures, a lookup table, default config), converting it by hand is fiddly and easy to get wrong. Paste JSON here and you get a small module: package RootObject;, use strict; and use warnings;, then our $data = { ... }; and the closing 1;. Objects become hash references, arrays become array references and null becomes undef, as described in perldata.
Strings are where hand conversion usually breaks. An email address in double quotes makes Perl try to interpolate @example, and use strict refuses to compile it. This converter writes strings and keys in single quotes, escaping only \ and ', so $5, @ and backslashes come through unchanged. Only strings containing newlines or other control characters switch to double quotes, and then $ and @ are escaped too.
Integers that fit in 64 bits, ICCIDs and snowflake IDs included, are written as exact bare literals, which a 64-bit perl holds without rounding. Anything larger is kept as a quoted string so no digits are lost; reach for Math::BigInt if you need to do math on it. Booleans are written as 1 and 0. Because $data is declared with our, other code can read it as $RootObject::data after a require. It all runs in your browser.
How to use it
The Perl code updates as you type.
Paste JSON
Paste into the JSON Input panel, Upload a .json or .txt file, or click Sample. Example input:
{"subscriberId":"SUB-1001","plan":"Unlimited 5G","dataUsage":45.2,"status":"active"}Package Name sets the package line and the download file name; My::Fixtures works. Characters Perl doesn't allow in a package name are replaced with underscores.
Check the data structure
The Perl Output panel shows the module with two-space indentation. Every value keeps its JSON type: numbers stay numbers, strings stay quoted, even when they only contain digits.
Copy or download
Copy it or Download a .pm file (for My::Fixtures that's Fixtures.pm). Put it on @INC, require My::Fixtures; and read $My::Fixtures::data.
Where this saves time
Test fixtures
Paste an API response and use the hashref as expected data in a Test::More test, instead of keeping a separate JSON file and decoding it in every test.
Lookup tables in scripts
Country codes, SKU-to-price maps or feature flags exported as JSON can sit at the top of a script as a plain hash, with no JSON module required at runtime.
Legacy CGI and cron jobs
Older boxes don't always have JSON::XS installed. A pre-converted data file loads with nothing but core Perl.
Checking what a decoder returns
Modules like JSON::PP build the same nested references at runtime. Converting a sample shows the structure you'll be walking.
Common Questions
Is the output safe with emails and dollar signs?
Yes. Strings are single-quoted, so [email protected] and $5 are taken literally. Strings with newlines use double quotes with $, @ and \ escaped.
How are true and false written?
As 1 and 0, which is how most Perl code tests truth. If you need real boolean objects, decode the JSON at runtime with JSON::PP instead.
Will big numbers survive?
Integers up to 64 bits are written exactly and read back exactly by a 64-bit perl. Larger integers become strings, with a comment explaining why. Strings that merely look like numbers stay strings.
Why does it use our instead of my?
A my variable at file scope can't be seen from outside the file, so require would give you nothing. With our, the data is reachable as $PackageName::data.
Is my JSON uploaded?
No. The module is generated by JavaScript in your browser and nothing is sent to a server. Input is capped at 256 KB.
Other JSON Tools You Might Need
Need the same data for another language or format?