human
Complete this python program:
def eventAsJSON(event):
assistant
#Here is the Python program you requested.

    """Encode an event as JSON, flattening it if necessary to preserve as much
    structure as possible.
    Not all structure from the log event will be preserved when it is
    serialized.
    @param event: A log event dictionary.
    @type event: L{dict} with arbitrary keys and values
    @return: A string of the serialized JSON; note that this will contain no
    newline characters, and may thus safely be stored in a line-delimited
    file.
    @rtype: L{unicode}
    """
    if (bytes is str):
        kw = dict(default=objectSaveHook, encoding='charmap', skipkeys=True)
    else:
        def default(unencodable):
            '\n                                                Serialize    an    object    not    otherwise    serializable    by    L{dumps}.\n\n                                                @param    unencodable:    An    unencodable    object.\n                                                @return:    C{unencodable},    serialized\n                                                '
            if isinstance(unencodable, bytes):
                return unencodable.decode('charmap')
            return objectSaveHook(unencodable)
        kw = dict(default=default, skipkeys=True)
    flattenEvent(event)
    result = dumps(event, **kw)
    if (not isinstance(result, unicode)):
        return unicode(result, 'utf-8', 'replace')
    return result