http://www.perlmonks.org?node_id=756287

Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Hi there monks,
I'm looking for a module on CPAN that can convert Javascript code snippets to JSON, apart from also doing the more common data-structure to JSON conversion. I've tried JSON::XS, ::Syck, ::PP and neither seem to be able to do this:

my $data = { age=>18, handler=>\"function(){ alert('hello, worldly') }" }; my $json = encode_json( $data )
And the output should look like this:
{ age: 18, handler: function(){ ... } }

But it usually converts it to: ...handler: "function(...)"

I know I've seen something that can do that somewhere. I think the usual implementation would use scalar references (ie \"function(){ }") to achieve this. But none of the regular JSON modules seem to accept it.

Any clues?
Thanks,
miguel