The encode_json method is used to encode a Perl value to JSON. This method is provided by the Mojo::JSON module, which provides methods to manipulate JSON.
encode_json $hash
Where the hash is the Perl value.
The encode_json method returns a JSON.
Let's look at an example of this method.
In the following example, we will try to encode the Perl value and print the returned JSON.
# import required packagesuse 5.010;use Data::Dumper;use Mojo::JSON qw(encode_json);# given Perl valuemy $hash = {scores => [40,90],name => 'John'};# encode the given Perl valuemy $json = encode_json $hash;# Print the returned JSONsay $json
hash to JSON.json.