JavaScript::HashRef::Decode - a JavaScript "data hashref" decoder for Perl
This module "decodes" a simple data-only JavaScript "object" and returns a Perl hashref constructed from the data contained in it.
It only supports "data" which comprises of: hashrefs, arrayrefs, single- and double-quoted strings, numbers, and "special" token the likes of "undefined", "true", "false", "null".
It does not support functions, nor is it meant to be an all-encompassing parser for a JavaScript object.
If you feel like the JavaScript structure you'd like to parse cannot effectively be parsed by this module, feel free to look into the Parse::RecDescent grammar of this module.
Patches are always welcome.
use JavaScript::HashRef::Decode qw<decode_js>; use Data::Dumper::Concise; my $js = q!{ foo: "bar", baz: { quux: 123 } }!; my $href = decode_js($js); print Dumper $href; { baz => { quux => 123 }, foo => "bar" }
decode_js($str)
Given a JavaScript object thing (i.e. an hashref), returns a Perl hashref structure which corresponds to the given data
decode_js('{foo:"bar"}');
Returns a Perl hashref:
{ foo => 'bar' }
The Parse::RecDescent internal interface is reused across invocations.
Parse::RecDescent
The ECMAScript Object specification: http://www.ecmascript.org/
Marco Fontani - MFONTANI@cpan.org
Aaron Crane
Copyright (c) 2013 Situation Publishing LTD
To install JavaScript::HashRef::Decode, copy and paste the appropriate command in to your terminal.
cpanm
cpanm JavaScript::HashRef::Decode
CPAN shell
perl -MCPAN -e shell install JavaScript::HashRef::Decode
For more information on module installation, please visit the detailed CPAN module installation guide.