diff --git a/scripts/ZoneMinder/lib/ZoneMinder/General.pm b/scripts/ZoneMinder/lib/ZoneMinder/General.pm index 90e7399ce..3d1dd0e49 100644 --- a/scripts/ZoneMinder/lib/ZoneMinder/General.pm +++ b/scripts/ZoneMinder/lib/ZoneMinder/General.pm @@ -432,13 +432,13 @@ our $testedJSON = 0; our $hasJSONAny = 0; sub _testJSON { - return if ( $testedJSON ); + return if $testedJSON; my $result = eval { require JSON::MaybeXS; JSON::MaybeXS->import(); }; $testedJSON = 1; - $hasJSONAny = 1 if ( $result ); + $hasJSONAny = 1 if $result; } sub _getJSONType { @@ -451,40 +451,41 @@ sub _getJSONType { return 'string'; } -sub jsonEncode; - sub jsonEncode { my $value = shift; _testJSON(); - if ( $hasJSONAny ) { - my $string = eval { JSON::MaybeXS->encode_json( $value ) }; - Fatal( "Unable to encode object to JSON: $@" ) unless( $string ); - return( $string ); + if ($hasJSONAny) { + my $string = eval { + JSON::MaybeXS->encode_json($value); + }; + Error('Unable to encode object to JSON: '.$@) unless $string; + return $string; } my $type = _getJSONType($value); - if ( $type eq 'integer' || $type eq 'double' ) { - return( $value ); - } elsif ( $type eq 'boolean' ) { - return( $value?'true':'false' ); + if ($type eq 'integer' || $type eq 'double') { + return '"'.$value.'"'; + } elsif ($type eq 'boolean') { + return $value ? 'true' : 'false'; } elsif ( $type eq 'string' ) { $value =~ s|(["\\/])|\\$1|g; $value =~ s|\r?\n|\n|g; - return( '"'.$value.'"' ); + return '"'.$value.'"'; } elsif ( $type eq 'null' ) { - return( 'null' ); + return 'null'; } elsif ( $type eq 'array' ) { - return( '['.join( ',', map { jsonEncode( $_ ) } @$value ).']' ); + return '['.join( ',', map { jsonEncode( $_ ) } @$value ).']'; } elsif ( $type eq 'hash' ) { my $result = '{'; - while ( my ( $subKey=>$subValue ) = each( %$value ) ) { + while ( my ( $subKey=>$subValue ) = each(%$value) ) { $result .= ',' if ( $result ne '{' ); - $result .= '"'.$subKey.'":'.jsonEncode( $subValue ); + $result .= '"'.$subKey.'":'.jsonEncode($subValue); } - return( $result.'}' ); + return $result.'}'; } else { - Fatal( "Unexpected type '$type'" ); + Error("Unexpected type '$type'"); + return ''; } }