Implement General::jsonLoad

This commit is contained in:
Isaac Connor 2022-02-08 10:14:00 -05:00
parent 2768975f96
commit a7dc9d4e36
1 changed files with 18 additions and 0 deletions

View File

@ -28,6 +28,7 @@ our %EXPORT_TAGS = (
makePath makePath
jsonEncode jsonEncode
jsonDecode jsonDecode
jsonLoad
systemStatus systemStatus
packageControl packageControl
daemonControl daemonControl
@ -536,6 +537,23 @@ sub jsonDecode {
return $result; return $result;
} }
sub jsonLoad {
my $file = shift;
my $json = undef;
eval {
require File::Slurp;
my $contents = File::Slurp::read_file($file);
if (!$contents) {
Error("No contents for $file");
return $json;
}
require JSON;
$json = JSON::decode_json($contents);
};
Error($@) if $@;
return $json;
}
sub parseNameEqualsValueToHash { sub parseNameEqualsValueToHash {
my %settings; my %settings;
foreach my $line ( split ( /\r?\n/, $_[0] ) ) { foreach my $line ( split ( /\r?\n/, $_[0] ) ) {