added a check for invalid utf-8 sequences when doing json_encode on the record. Fixed unittests.