diff --git a/modules/util/Util/JSON.pm b/modules/util/Util/JSON.pm index 055e45de588cdc9703902657e07626980d1944fe..bc42cc84ffeb57a379112eeb27b102bf528fc8ff 100755 --- a/modules/util/Util/JSON.pm +++ b/modules/util/Util/JSON.pm @@ -3,6 +3,7 @@ package Util::JSON; use strict; +use File::Slurper qw(read_text write_text); use JSON -convert_blessed_universally; sub read_json_file @@ -12,10 +13,19 @@ sub read_json_file # BEGIN load JSON data from file content local $/; # print "reading config [$fnm]\n"; + +=begin comment + open( my $fh, '<:utf8', $fnm ) or return undef; my $json_text = <$fh>; close ($fh); # decode_json( $json_text ); # for some reason, decode_json() barfs when otherwise cleanly read wide characters are present + +=end comment +=cut + + my $json_text= read_text($fnm); + from_json($json_text); } @@ -30,10 +40,18 @@ sub write_json_file my $json= new JSON; my $json_str= $json->allow_blessed->convert_blessed->encode($x); +=begin comment + open (J, '>:utf8', $json_fnm) or die ("can not write to [$json_fnm]"); syswrite (J, $json_str); close (J); + +=end comment +=cut + + write_text($fnm, $json_str); + 1; } @@ -52,6 +70,12 @@ sub get_config_item __END__ +=head1 DEPENDENCIES + +=head2 Ubuntu + +sudo apt-get install libfile-slurper-perl + =head1 AUTHOR Gerhard Gonter <ggonter@cpan.org>