NAME

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

SYNOPSIS

use Inline::JSON;

my $json = json: {
    "name":   "Awesome",
    "title":  "Mr.",
    "skills": [
        "Nunchucking",
        "Bowhunting",
        "Computer Hacking",
        "Being Awesome",
    ]
};

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

Yields the output like:

$VAR1 = {
           'name' => 'Awesome',
           'title' => 'Mr.',
           'skills' => [
                         "Nunchucking",
                         "Bowhunting",
                         "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 = [
    {
        "id": "1",
        "name": "one",
    },
    {
        "id": "2",
        "name": "two",
    },
    {
        "id": "3",
        "name": "three",
    },
];

DESCRIPTION

JSON is a data specification format used for interoperability with a multitude of languages. Sometimes you have a chunk of YAML 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.

CAVEATS

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.

SEE ALSO

JSON

The module being used to parse the JSON content.

Inline::YAML

The inspiration for this module.

AUTHOR

Anthony Kilna, <anthony at kilna.com> - http://anthony.kilna.com

BUGS

Please report any bugs or feature requests to bug-inline-json at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Inline-JSON. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT

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

perldoc Inline::JSON

You can also look for information at:

ACKNOWLEDGEMENTS

LICENSE AND COPYRIGHT

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 http://dev.perl.org/licenses/ for more information.