my $rows = reader($mysqlFilename); ...in reader my $json = encode_json($hashref, { lastname => JSON_TYPE_STRING, firstname => JSON_TYPE_STRING, age => JSON_TYPE_INT} ); ...and I return $json which is the single record.