import json


def serialize_json_lines(f, data, **kwargs):
    """
    json newline delimited message encoding strategy
    :param f: a file handle or iterable of bytes
    :param iterable data:
    """
    record_count = 0
    for record in data:
        f.write(json.dumps(record).encode("utf-8") + b"\n")
        record_count += 1
    return record_count