import pathlib
import json


def dump(obj, path, **kw):
    """`json.dump` which understands filenames.

    :param obj: The object to be dumped.
    :param path: The path of the JSON file to be written.
    :param kw: Keyword parameters are passed to json.dump
    """
    # avoid indented lines ending with ", " on PY2
    if kw.get('indent') and kw.get('separators') is None:
        kw['separators'] = (',', ': ')

    with pathlib.Path(path).open('w', encoding='utf-8') as fp:
        return json.dump(obj, fp, **kw)