NAME

Data::AnyXfer::JSON - functions for encoding/decoding JSON

SYNOPSIS

use utf8; # source code contains UTF-8

use Data::AnyXfer::JSON qw/ decode_json /;

my $json = encode_json( { price => '£185pcm' } );

my $hash = decode_json( $json );

DESCRIPTION

This module provides simple wrappers around Cpanel::JSON::XS that ensure JSON strings are encoded as UTF-8 before decoding them.

EXPORTS

encode_json

my $json = encode_json( { price => '£185pcm' } );

Return UTF-8 encoded JSON.

encode_json_pretty

my $json = encode_json_pretty( { price => '£185pcm' } );

Return UTF-8 encoded multi-line formatted / pretty JSON.

decode_json

my $hash = decode_json( $json );

Decode a JSON string. Automatically encodes it to UTF-8.

decode_json_file

my $hash = decode_json_file( $json_file );

Decode the contents of a file as a JSON string.

Automatically encodes it to UTF-8.

decode_json_handle

my $hash = decode_json_handle( $json_fh );

Decode the contents of a file handle as a JSON string.

Automatically encodes it to UTF-8.

is_bool

true

false

See Cpanel::JSON::XS.

COPYRIGHT

This software is copyright (c) 2019, Anthony Lucas.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.