def _process_file(path, formatting=None, verbose=False):
    """Check syntax/formatting and fix formatting of a JSON file.

    :param formatting: one of 'check' or 'fix' (default: None)

    Raises ValueError if JSON syntax is invalid or reformatting needed.
    """
    with open(path, 'r') as infile:
        raw = infile.read()
        try:
            parsed = _parse_json(raw)
        except ParserException as err:
            raise ValueError(err)
        else:
            if formatting in ('check', 'fix'):
                formatted = _format_parsed_json(parsed)
                if formatted != raw:
                    if formatting == "fix":
                        with open(path, 'w') as outfile:
                            outfile.write(formatted)
                        if verbose:
                            print("%s\n%s" % (path,
                                              _indent_note("Reformatted")))
                    else:
                        raise ValueError("Reformatting needed")
            elif formatting is not None:
                # for the benefit of external callers
                raise ValueError("Called with invalid formatting value.")
dataset/ETHPy150Open openstack/openstack-doc-tools/os_doc_tools/jsoncheck.py/_process_file/original