From: miker Date: Fri, 15 Jul 2005 19:52:09 +0000 (+0000) Subject: remove extranious "null"s from JSON X-Git-Tag: osrf_rel_2_0_1~1473 X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=c12f80bfead026c312e2ba615e3be986a81554bc;p=OpenSRF.git remove extranious "null"s from JSON git-svn-id: svn://svn.open-ils.org/OpenSRF/trunk@399 9efc2488-bf62-4759-914b-345cdb29e865 --- diff --git a/src/perlmods/JSON.pm b/src/perlmods/JSON.pm index cbb03f7..9d6d8b4 100644 --- a/src/perlmods/JSON.pm +++ b/src/perlmods/JSON.pm @@ -172,21 +172,22 @@ sub old_JSON2perl { } sub perl2JSON { - my ($class, $perl) = @_; + my ($class, $perl, $strict) = @_; my $output = ''; if (!defined($perl)) { - $output = 'null'; + $output = '' unless $strict; + $output = 'null' if $strict; } elsif (ref($perl) and ref($perl) =~ /^JSON/) { $output .= $perl; } elsif ( ref($perl) && exists($_class_map{classes}{ref($perl)}) ) { $output .= '/*--S '.$_class_map{classes}{ref($perl)}{hint}.'--*/'; if (lc($_class_map{classes}{ref($perl)}{type}) eq 'hash') { my %hash = %$perl; - $output .= perl2JSON(undef,\%hash); + $output .= perl2JSON(undef,\%hash, $strict); } elsif (lc($_class_map{classes}{ref($perl)}{type}) eq 'array') { my @array = @$perl; - $output .= perl2JSON(undef,\@array); + $output .= perl2JSON(undef,\@array, $strict); } $output .= '/*--E '.$_class_map{classes}{ref($perl)}{hint}.'--*/'; } elsif (ref($perl) and ref($perl) =~ /HASH/) { @@ -195,7 +196,7 @@ sub perl2JSON { for my $key (sort keys %$perl) { $output .= ',' if ($c); - $output .= perl2JSON(undef,$key).':'.perl2JSON(undef,$$perl{$key}); + $output .= perl2JSON(undef,$key, $strict).':'.perl2JSON(undef,$$perl{$key}, $strict); $c++; } $output .= '}'; @@ -205,7 +206,7 @@ sub perl2JSON { for my $part (@$perl) { $output .= ',' if ($c); - $output .= perl2JSON(undef,$part); + $output .= perl2JSON(undef,$part, $strict); $c++; } $output .= ']'; @@ -213,7 +214,7 @@ sub perl2JSON { my $type = $2; my $name = $1; JSON->register_class_hint(name => $name, hint => $name, type => lc($type)); - $output .= perl2JSON(undef,$perl); + $output .= perl2JSON(undef,$perl, $strict); } else { $perl =~ s{\\}{\\\\}sgo; $perl =~ s/"/\\"/sgo;