sub json() { my $obj="["; my $n=20; for(my $i=0;$i<$n;$i++) { $obj.="{ \"id\":\"stu_$i\", "; $obj.="\"is Active\":true,\"name\":\"studentname$i\","; $obj.="\"address\":".getaddr(); $obj.="\"qualifications\":".getqualifications(); my $k=int(rand(20))+20; $obj.="\"age\":$k,"; $obj.="\"gender\":\"male\","; $obj.="\"email\":".getemail(); $obj.="\"about\":".getabout(); $obj.="\"rgistered\":\"".localtime()."\","; $obj.="\"phone\":".getphone(); $obj.=getstandctry(); $obj.="\"subjects\":".getsubjects().","; $obj.="\"subjects2\":".getsubjects(); $obj.="},"; } chop($obj) if $obj=~ m(,$); #if (is_json_valid($obj)) # { # print " ... do something ..."; # } my $data_structure = from_json($obj); print Dumper($data_structure) ; writetofile($data_structure); }