import json
from contextlib import contextmanager
from pathlib import Path
from typing import Any, Generator


@contextmanager
def readlines(path: Path | str) -> Generator[Any, None, None]:
    """Return the lines from a JSON."""
    if isinstance(path, str):
        path = Path(path)

    if not path.exists():
        yield iter(())
        return None

    with open(path) as fp:
        yield (json.loads(line) for line in fp)
