def main(args=None):
    if args is None:
        args = sys.argv[1:]
    default_schema = None
    if os.path.exists(SCHEMA):
        default_schema = SCHEMA

    parser = argparse.ArgumentParser(
                description=textwrap.dedent(main.__doc__),
                formatter_class=argparse.RawDescriptionHelpFormatter
    )
    parser.add_argument("-v", "--version",
                        action="version", version=__version__)
    parser.add_argument("-s", "--schema",
                        help="JSON schema to use.")
    parser.add_argument("-e", "--encoding",
                        help="Encoding for JSON/JSON schema.")
    parser.add_argument("files", nargs="+", metavar="JSON_FILE",
                        help="JSON file to check.")
    parser.set_defaults(
            schema=default_schema,
            encoding="UTF-8"
    )
    options = parser.parse_args(args)
    if not options.schema:
        parser.error("REQUIRE: JSON schema")
    elif not os.path.isfile(options.schema):
        parser.error("SCHEMA not found: %s" % options.schema)

    try:
        f = open(options.schema, "r")
        contents = f.read()
        f.close()
        schema = json.loads(contents, encoding=options.encoding)
    except Exception as e:
        msg = "ERROR: %s: %s (while loading schema)" % (e.__class__.__name__, e)
        sys.exit(msg)

    error_count = 0
    for filename in options.files:
        validated = True
        more_info = None
        try:
            print("validate:", filename, "...", end=' ')
            jsonschema_validate(filename, schema, encoding=options.encoding)
        except Exception as e:
            more_info = "%s: %s" % (e.__class__.__name__, e)
            validated = False
            error_count += 1
        if validated:
            print("OK")
        else:
            print("FAILED\n\n%s" % more_info)
    return error_count


# -----------------------------------------------------------------------------
# AUTO-MAIN
# -----------------------------------------------------------------------------
Validate JSON files against their JSON schema.
dataset/ETHPy150Open behave/behave/bin/jsonschema_validate.py/main