<SYSTEM_TASK:>
Solve the following problem using Python, implementing the functions described below, one line at a time
<END_TASK>
<USER_TASK:>
Description:
 def write_json_flag(flag, fobj, **kwargs):
 """Write a `DataQualityFlag` to a JSON file Parameters flag : `DataQualityFlag` data to write fobj : `str`, `file` target file (or filename) to write **kwargs other keyword arguments to pass to :func:`json.dump` See also -------- json.dump for details on acceptable keyword arguments """

    # write to filename
    if isinstance(fobj, string_types):
        with open(fobj, 'w') as fobj2:
            return write_json_flag(flag, fobj2, **kwargs)

    # build json packet
    data = {}
    data['ifo'] = flag.ifo
    data['name'] = flag.tag
    data['version'] = flag.version
    data['active'] = flag.active
    data['known'] = flag.known
    data['metadata'] = {}
    data['metadata']['active_indicates_ifo_badness'] = not flag.isgood
    data['metadata']['flag_description'] = flag.description

    # write
    json.dump(data, fobj, **kwargs)