Inline::JSON - Embed JSON data structures directly into your Perl code
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 = 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 kilna.com> - http://anthony.kilna.com
<anthony at kilna.com>
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.
bug-inline-json at rt.cpan.org
You can find documentation for this module with the perldoc command.
perldoc Inline::JSON
You can also look for information at:
RT: CPAN's request tracker (report bugs here)
http://rt.cpan.org/NoAuth/Bugs.html?Dist=Inline-JSON
AnnoCPAN: Annotated CPAN documentation
http://annocpan.org/dist/Inline-JSON
CPAN Ratings
http://cpanratings.perl.org/d/Inline-JSON
Search CPAN
http://search.cpan.org/dist/Inline-JSON/
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.
To install Inline::JSON, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Inline::JSON
CPAN shell
perl -MCPAN -e shell install Inline::JSON
For more information on module installation, please visit the detailed CPAN module installation guide.