Anthony Kilna


Inline::JSON - Embed JSON data structures directly into your Perl code


    use Inline::JSON;

    my $json = json: {
        "name":   "Awesome",
        "title":  "Mr.",
        "skills": [
            "Computer Hacking",
            "Being Awesome",

    use Data::Dumper;
    print Dumper($json);

Yields the output like:

    $VAR1 = {
               'name' => 'Awesome',
               'title' => 'Mr.',
               'skills' => [
                             'Computer Hacking',
                             'Being Awesome',

You can also specify array references as the top-level JSON element, by using brackets instead of curly braces:

    my $list_of_hashrefs = json: [
            "id": "1",
            "name": "one",
            "id": "2",
            "name": "two",
            "id": "3",
            "name": "three",


JSON is a data specification format used for interoperability with a multitude of languages. Sometimes you have a chunk of JSON that you need to turn into a Perl data structure. This module allows you to specify that code inline within your perl program. It is syntactic sugar on top of the existing JSON module, you could just as easily say:

   my $json = JSON->new->decode('{
       // JSON code here

Which is what the module is doing internally, it just looks nicer.


This module uses simple balanced brackets or curly braces matching to determine the end of the chunk of JSON code, and does not pay attention to quotes. If you have curly braces embedded in the strings in your JSON code, it can cause the filter to misinterpret the end of the JSON.

If you'd like to see what the filtered perl code looks like after the source filter has been run on it, set the variable $Inline::JSON::DEBUG to a true value prior to the 'use Inline::JSON' statement.



The module being used to parse the JSON content.


The inspiration for this module.


Anthony Kilna, <anthony at> -


Please report any bugs or feature requests to bug-inline-json at, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


You can find documentation for this module with the perldoc command.

    perldoc Inline::JSON

You can also look for information at:



Copyright 2012 Kilna Companies.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See for more information.