#!/opt/lampp/bin/perl use CGI; use JSON; use utf8; ##### S U B S ######### sub speaker { my $text = shift; print "Content-type: text/html\n\n"; print $text; } ###################################################### #Extracts contents from JSON file, no extra mods required sub extract_json { my $file = shift; my $jobject = ""; open ( FH, "< $file") || die "Can`t open file: $!\n"; while ( ){ $jobject .= $_; } close FH or die "Can`t close FH: $!\n"; return $jobject; } #################################################### sub record { my ($name, $mail, $pass, $file) = @_; if ( $name && $mail && $pass ) { my $fromj = extract_json($file); #all well to here my $json = decode_json($fromj); print $json[0]->[0]{"name"}; } } ################################################### my $jobj = extract_json("dat.json"); my $perl_data = decode_json($jobj); my $jobject = encode_json($perl_data); my @perl_data2 = decode_json($jobject); my $len = @perl_data2; print "Size of perl_data2 is $len \n"; $perl_data2[0]->[6] = {"name","boho", "age",31, "id",987654 }; $perl_data2[0]->[5]={"name","dodo", "age",31, "id", 987654 }; $perl_data2[0]->[4] ={"name","pupo", "age",31, "id", 987654 }; $perl_data2[1]->[0] ={"ver",2222, "beta" ,"yes", "id", 987654 }; $jobject = encode_json($perl_data2[0]); open(FH, ">df.json"); print FH $jobject; close(FH); for ( $i=0; @perl_data2->[0][$i]; $i++ ) { print $perl_data2[0]->[$i]{"name"}, "\n"; }