Skip to content

Instantly share code, notes, and snippets.

@akzhan akzhan/

Created Dec 28, 2016
What would you like to do?
package BUX::Util::JSON;
=encoding utf-8
=head1 NAME
use BUX::Util::JSON qw( data_to_json data_from_json );
Получает на вход JSON в виде строки с флагом utf-8.
Или возвращает JSON в виде строки с флагом utf-8.
use strict;
use warnings;
use utf8;
use JSON::XS ();
use Encode qw( encode_utf8 decode_utf8 );
use Exporter qw( import );
my $jsoner = JSON::XS->new->utf8->allow_nonref;
=head1 METHODS
=head2 data_to_json
my $json_str = data_to_json( $scalar_or_ref );
sub data_to_json {
return decode_utf8( $jsoner->encode( $_[0] ) );
=head2 data_from_json
my $scalar_or_ref = data_from_json( $json_str );
sub data_from_json {
return $jsoner->decode( encode_utf8( $_[0] ) );
our @EXPORT_OK = qw(
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.