def lines_per_n(f, n):
    for line in f:
        yield ''.join(chain([line], itertools.islice(f, n - 1)))
Python: Trying to Deserialize Multiple JSON objects in a file with each object spanning multiple but consistently spaced number of lines