hash_to_json perl

PHOTO EMBED

Sun Dec 27 2020 16:04:43 GMT+0000 (Coordinated Universal Time)

Saved by @lynx74br #perl

sub hash_to_json {
	my $h = shift;
	use Data::Dumper;
	$Data::Dumper::Sortkeys = 1;
	$Data::Dumper::Pair = ":";
	$Data::Dumper::Indent = 0;
	$Data::Dumper::Terse = 1;
	$Data::Dumper::Useqq = '"';
	$_ = Dumper( $h );
	s/:undef/:null/g;
	print "$_\n";
}

my %json;
$json{status}='200';
$json{order}=1001;
$json{null}=undef;
$json{email}='test@test.com';
$json{data}[0]{id}=1;
$json{data}[0]{prod}='Notebook';
$json{data}[0]{value}=543.21;
$json{data}[1]{id}=2;
$json{data}[1]{prod}='Bad';
$json{data}[1]{value}=12.45;
hash_to_json(\%json);
content_copyCOPY