Returns the records serialized as Transit/json in utf8

def encode_transit(records):
    '''Returns the records serialized as Transit/json in utf8'''
    with StringIO() as buf:
        writer = Writer(buf, "json")
        writer.write(records)
        return buf.getvalue().encode('utf8')