use IO::File; use JSON::Streaming::Reader; sub is_valid_json { my $fh = IO::File->new(shift, "r"); my $jsonr = JSON::Streaming::Reader->for_stream($fh); my @ignore = map {($_, sub {})} qw(start_array end_array start_object add_string add_number add_boolean add_null end_object start_property end_property); eval {$jsonr->process_tokens(@ignore, error => sub {die "@_"})}; return !$@; } print is_valid_json('file.json') ? 'ok' : 'panic';