import io
import json


def dump(obj, fp, **kwargs):
    """
    Serialize `obj` as a JSON formatted stream to `fp` (a
    `.write()`-supporting file-like object). Accepts the same arguments as
    `json` module in stdlib.

    :param obj: a JSON serializable Python object.
    :param fp: a `.read()`-supporting file-like object containing a JSON
               document with or without comments.
    :param kwargs: all the arguments that `json.dump <http://docs.python.org/
                   2/library/json.html#json.dump>`_ accepts.
    """
    if not isinstance(fp, io.IOBase):
        raise TypeError('second argument must be file-type (IOBase) got: {}'.format(type(fp)))

    return json.dump(obj, fp, **kwargs)