The decode_json
method is used to decode JSON to Perl value. This method is provided by the module Mojo::JSON
which provides methods to manipulate JSON.
decode_json $json;
Where $json
is the JSON string.
The method returns a Perl hash
.
In the following example, we will try to decode the JSON string and print the returned Perl hash.
# import required packagesuse 5.010;use Data::Dumper;use Mojo::JSON qw(decode_json);# given json stringmy $json = '{"name":"John","scores":[40,90]}';# decode the given jsonmy $hash = decode_json $json;# Print the returned hashprint Dumper($hash);
In the above code snippet,
json
.json
, using the decode_json
method, and store it in the hash
variable.Dumper
function, provided by the Data::Dumper
module.