The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

JavaScript::HashRef::Decode - a JavaScript "data hashref" decoder for Perl

SYNOPSIS

    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"
    }

EXPORTED SUBROUTINES

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.

CAVEATS & BUGS

STRINGS

JavaScript string interpolation only works for the following escaped values: \", \', \n, \t.

KEYS

JavaScript keys cannot be strings or numbers, but an "identifier" which starts with a letter or underscore, and contains letters, underscores or numbers afterwards.

SEE ALSO

Parse::RecDescent

AUTHOR

Marco Fontani - MFONTANI@cpan.org

COPYRIGHT

Copyright (c) 2013 Situation Publishing LTD