def read_json_flag(fobj):
    """Read a `DataQualityFlag` from a segments-web.ligo.org JSON file
    """
    # read from filename
    if isinstance(fobj, string_types):
        with open(fobj, 'r') as fobj2:
            return read_json_flag(fobj2)

    # read from open file
    txt = fobj.read()
    if isinstance(txt, bytes):
        txt = txt.decode('utf-8')
    data = json.loads(txt)

    # format flag
    name = '{ifo}:{name}:{version}'.format(**data)
    out = DataQualityFlag(name, active=data['active'],
                          known=data['known'])

    # parse 'metadata'
    try:
        out.description = data['metadata'].get('flag_description', None)
    except KeyError:  # no metadata available, but that's ok
        pass
    else:
        out.isgood = not data['metadata'].get(
            'active_indicates_ifo_badness', False)

    return out
Read a `DataQualityFlag` from a segments-web.ligo.org JSON file