An(other) implementation of JSON Schema for Python

Overview

jsonschema

PyPI version Supported Python versions Build status ReadTheDocs status

jsonschema is an implementation of JSON Schema for Python.

>>> from jsonschema import validate

>>> # A sample schema, like what we'd get from json.load()
>>> schema = {
...     "type" : "object",
...     "properties" : {
...         "price" : {"type" : "number"},
...         "name" : {"type" : "string"},
...     },
... }

>>> # If no exception is raised by validate(), the instance is valid.
>>> validate(instance={"name" : "Eggs", "price" : 34.99}, schema=schema)

>>> validate(
...     instance={"name" : "Eggs", "price" : "Invalid"}, schema=schema,
... )                                   # doctest: +IGNORE_EXCEPTION_DETAIL
Traceback (most recent call last):
    ...
ValidationError: 'Invalid' is not of type 'number'

It can also be used from console:

$ jsonschema --instance sample.json sample.schema

Features

Installation

jsonschema is available on PyPI. You can install using pip:

$ pip install jsonschema

Running the Test Suite

If you have tox installed (perhaps via pip install tox or your package manager), running tox in the directory of your source checkout will run jsonschema's test suite on all of the versions of Python jsonschema supports. If you don't have all of the versions that jsonschema is tested under, you'll likely want to run using tox's --skip-missing-interpreters option.

Of course you're also free to just run the tests on a single version with your favorite test runner. The tests live in the jsonschema.tests package.

Benchmarks

jsonschema's benchmarks make use of pyperf. Running them can be done via:

$ tox -e perf

Community

The JSON Schema specification has a Slack, with an invite link on its home page. Many folks knowledgeable on authoring schemas can be found there.

Otherwise, asking questions on Stack Overflow is another means of getting help if you're stuck.

Contributing

I'm Julian Berman.

jsonschema is on GitHub.

Get in touch, via GitHub or otherwise, if you've got something to contribute, it'd be most welcome!

You can also generally find me on Freenode (nick: tos9) in various channels, including #python.

If you feel overwhelmingly grateful, you can also woo me with beer money via Google Pay with the email in my GitHub profile.

And for companies who appreciate jsonschema and its continued support and growth, jsonschema is also now supportable via TideLift.

Comments
  • Draft 4 support

    Draft 4 support

    I started writing up a bit of code for the current revision of draft 4. Branch is here I haven't done any testing, or added unit tests, so it is liable to be broken, just thought I'd let people know I'm working on it.

    Enhancement 
    opened by gazpachoking 44
  • Port the Test Suite to JSON

    Port the Test Suite to JSON

    We discussed it a bit over here, just wanted to get your input on what sort of format you think the tests should be in? Should they be defined in json, maybe something like this?

    {
        "name": "integer",
        "version": ["draft 3", "draft 4"],
        "schema": {"type": "integer"},
        "tests": [
            ["integer", 1, "valid"],
            ["number", 1.1, "invalid"]
        ]
    }
    
    Enhancement 
    opened by gazpachoking 40
  • More info in ValidationErrors

    More info in ValidationErrors

    In my project, I want to create user facing error messages which are friendlier than the default ones. I'm thinking we could attach the instance value, as well as the value for the schema keyword that failed to the ValidationError to facilitate this.

    The instance could already be grabbed by walking the path through the instance, but it would be a bit easier if it is already attached.

    opened by gazpachoking 38
  • $ref resolution scope

    $ref resolution scope

    Currently the RefResolver does not alter the resolution scope when the "id" keyword is encountered. This can lead to problems when dereferencing. Consider the following schema:

    {
        "id": "http://somewhere/schema.json",
        "definitions": {
            "subschema": {
                "id": "subschema.json",
                "definitions": {
                    "subsubschema1": {},
                    "subsubschema2": {"$ref": "#/definitions/subsubschema1"}
                }
            }
        }
    }
    

    Currently we would resolve the ref as http://somewhere/schema.json#/definitions/subsubschema1, which would cause a RefResolutionError as it does not exist. The proper resolution would be http://somewhere/subschema.json#/definitions/subsubschema1.

    This is the same issue #60 is trying to address, but that PR doesn't actually solve the problem fully. What I was calling 'context' in that ticket, is actually called 'resolution scope' in the specification, and it needs to change both when we are inside a remote reference (which is what that PR currently covers,) as well as when we encounter an id keyword in the same schema (which is not covered in that PR.)

    Bug 
    opened by gazpachoking 36
  • [DRAFT] #708 - Make pretty formatter output prettier

    [DRAFT] #708 - Make pretty formatter output prettier

    Fixes #708.

    This makes the pretty output look better by making error header and footer lines equal lengths and to use Unicode characters in them. It also shows schema JSON in error messages as valid JSON, not Python data structure representations. (Mostly a difference in quote marks used for strings.)

    For the error messages, I wanted to continue using the strings with str.format(). However, I couldn't find a clean way of using the left justification and padding that's available in the formatting micro-language. If the technique I used isn't satisfactory, I can try for another approach.

    To get the schema instance to display as true JSON, I thought encoding the schema back to JSON was the best approach. Using newline with the separator and sorting keys seems to give close to the same output format as pprint.pformat(). The difference is that it ends up being a little prettier, because there are always line breaks, but in my testing, pprint only broke the lines when the schema was longer than 72 characters. I didn't test extensively, so I don't know how well the json.dumps() technique compares with pprint for lines that longer than 72 characters and aren't easily broken.

    Please feel free to be critical with the code review. I'm very much open to updating my changes to fit with the style of the project.

    opened by sloanlance 33
  • Ref resolution scope

    Ref resolution scope

    Okay, I think this resolves :stuck_out_tongue_winking_eye: the issue mentioned in #66. It at least passes the tests I have at https://github.com/json-schema/JSON-Schema-Test-Suite/pull/34

    @Julian, how do you feel about this method?

    Bug 
    opened by gazpachoking 31
  • Add a context manager to RefResolver

    Add a context manager to RefResolver

    @Julian Still need to come up with some more tests, and fix one current test to work with the new method to make sure this is working as intended. Just wanted to get your thoughts on this method of handling nested $ref resolution before proceeding.

    Enhancement 
    opened by gazpachoking 27
  • Ensure jsonschema's extension mechanisms support enough for implementing $data as an end user

    Ensure jsonschema's extension mechanisms support enough for implementing $data as an end user

    $data proposal implemented by AJV allows validation based on another value. It can drastically reduce the amount of custom coded performed after the schema has been validated.

    Additionally, interoperability with AJV would allow to quickly implement UIs with AJV-based form generators such as VueFormJsonSchema or similar solutions.

    Enhancement 
    opened by naquad 26
  • draft-06 Support

    draft-06 Support

    Is it in plan to support draft-06?

    in my Project i need to use propertyNames to validate object keys agains regex pattern. but propertyNames was introduced in draft-06.

    for now i am using patternProperties with "additionalProperties": False together, but the error is confusing because of "schema does not allow additional properties"

    opened by khakulov 26
  • $ref attribute

    $ref attribute

    Hello Julian,

    Are you planning to implement support of $ref attribute in your library? $ref attribute gives a lot of flexibility in building schemas for validating dynamic JSONs.

    Thanks.

    Enhancement 
    opened by psihonavt 26
  • When open()'ing file, encoding needs to be specified. Was: A strange issue with jsonschema in docker.

    When open()'ing file, encoding needs to be specified. Was: A strange issue with jsonschema in docker.

    Hi.

    So this will probably turn out to be a my local problem, but i'm not seeing it just yet.

    I'm using jsonschema to validate a JSON file in darktable: https://github.com/darktable-org/darktable/blob/master/data/CMakeLists.txt#L99

    On my local machine this just works:

    $ make validate_noiseprofiles_json 
    Checking validity of noiseprofiles.json
    Built target validate_noiseprofiles_json
    

    However in clean docker environment it does not: https://travis-ci.org/darktable-org/darktable/jobs/163489568#L520

    [  4%] Checking validity of noiseprofiles.json
    usage: jsonschema [-h] [-i INSTANCES] [-F ERROR_FORMAT] [-V VALIDATOR] schema
    jsonschema: error: argument -i/--instance: invalid _json_file value: '/build/darktable/data/noiseprofiles.json'
    

    If i manually pull that image, and do it manually, it does cause the same issue. And outside of the image, it just works. On the exact same input JSON+schema, with exactly the same sha512sum's for those 2 files.

    What could possibly be going on?

    opened by LebedevRI 23
  • Error when using enum

    Error when using enum

    Hi there I'm using a Json Schema with Version 2020-12 that includes enums. I do get the following error:

    jsonschema.exceptions.SchemaError: ('=', '>', '<', '>=', '<=', '<>', '!=', '==', 'between', 'in') is not of type 'array'

    VS Code does not complain about the schema so it seems like a but in jschonschema?

    Here's my json schema:

    {
        "type": "array",
        "items": {
            "$ref": "#/$defs/Config"
        },
        "$defs": {
            "Column": {
                "type": "object",
                "required": [
                    "name"
                ],
                "additionalProperties": false,
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "alias": {
                        "type": [
                            "string",
                            "null"
                        ]
                    }
                }
            },
            "GroupByExpConfig": {
                "type": "object",
                "required": [],
                "additionalProperties": false,
                "properties": {
                    "col": {
                        "type": "string"
                    },
                    "func": {
                        "enum": [
                            "sum",
                            "count",
                            "mean",
                            "median",
                            "min",
                            "max",
                            "first",
                            "std",
                            "n_unique",
                            "distinct",
                            "mode",
                            "null_count"
                        ]
                    },
                    "alias": {
                        "type": [
                            "string",
                            "null"
                        ]
                    }
                }
            },
            "GroupByConfig": {
                "type": "object",
                "required": [
                    "by",
                    "expressions"
                ],
                "additionalProperties": false,
                "properties": {
                    "by": {
                        "type": "array",
                        "items": {
                            "type": "string"
                        }
                    },
                    "expressions": {
                        "type": "array",
                        "items": {
                            "$ref": "#/$defs/GroupByExpConfig"
                        }
                    }
                }
            },
            "SortBy": {
                "type": "object",
                "required": [
                    "by"
                ],
                "additionalProperties": false,
                "properties": {
                    "by": {
                        "type": "string"
                    },
                    "direction": {
                        "enum": [
                            "asc",
                            "desc"
                        ]
                    }
                }
            },
            "Join": {
                "type": "object",
                "required": [
                    "uri",
                    "left_on",
                    "right_on"
                ],
                "additionalProperties": false,
                "properties": {
                    "uri": {
                        "type": "string"
                    },
                    "left_on": {
                        "type": "string"
                    },
                    "right_on": {
                        "type": "string"
                    },
                    "file_type": {
                        "enum": [
                            "delta",
                            "parquet",
                            "arrow",
                            "avro",
                            "csv",
                            "json",
                            "ndjson"
                        ]
                    },
                    "how": {
                        "enum": [
                            "inner",
                            "left",
                            "outer",
                            "semi",
                            "anti",
                            "cross"
                        ]
                    },
                    "suffix": {
                        "type": "string"
                    }
                }
            },
            "Filter": {
                "type": "object",
                "required": [
                    "key",
                    "operator",
                    "value"
                ],
                "additionalProperties": false,
                "properties": {
                    "key": {
                        "type": "string"
                    },
                    "operator": {
                        "enum": [
                            "=",
                            ">",
                            "<",
                            ">=",
                            "<=",
                            "<>",
                            "!=",
                            "==",
                            "between",
                            "in"
                        ]
                    },
                    "value": {
                        "oneOf": [
                            {},
                            {
                                "type": "array",
                                "minItems": 2,
                                "maxItems": 2,
                                "additionalItems": false,
                                "prefixItems": [
                                    {},
                                    {}
                                ]
                            }
                        ]
                    }
                }
            },
            "DataframeConfig": {
                "type": "object",
                "required": [
                    "uri"
                ],
                "additionalProperties": false,
                "properties": {
                    "uri": {
                        "type": "string"
                    },
                    "file_type": {
                        "enum": [
                            "delta",
                            "parquet",
                            "arrow",
                            "avro",
                            "csv",
                            "json",
                            "ndjson"
                        ]
                    },
                    "select": {
                        "type": "array",
                        "items": {
                            "$ref": "#/$defs/Column"
                        }
                    },
                    "groupby": {
                        "oneOf": [
                            {
                                "type": "null"
                            },
                            {
                                "$ref": "#/$defs/GroupByConfig"
                            }
                        ]
                    },
                    "sortby": {
                        "type": "array",
                        "items": {
                            "$ref": "#/$defs/SortBy"
                        }
                    },
                    "joins": {
                        "type": "array",
                        "items": {
                            "$ref": "#/$defs/Join"
                        }
                    },
                    "filters": {
                        "type": "array",
                        "items": {
                            "$ref": "#/$defs/Filter"
                        }
                    },
                    "cache_expiration_time_seconds": {
                        "type": [
                            "integer",
                            "null"
                        ]
                    },
                    "in_memory": {
                        "type": [
                            "boolean",
                            "null"
                        ]
                    }
                }
            },
            "Param": {
                "type": "object",
                "required": [
                    "name",
                    "type"
                ],
                "additionalProperties": false,
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "type": {
                        "type": "string"
                    },
                    "default": {
                        "type": [
                            "string",
                            "null"
                        ]
                    }
                }
            },
            "Config": {
                "type": "object",
                "required": [
                    "name"
                ],
                "additionalProperties": false,
                "properties": {
                    "name": {
                        "type": "string"
                    },
                    "tag": {
                        "type": [
                            "string",
                            "null"
                        ]
                    },
                    "route": {
                        "type": [
                            "string",
                            "null"
                        ]
                    },
                    "dataframe": {
                        "oneOf": [
                            {
                                "type": "null"
                            },
                            {
                                "$ref": "#/$defs/DataframeConfig"
                            }
                        ]
                    },
                    "version": {
                        "type": [
                            "integer",
                            "null"
                        ]
                    },
                    "api_method": {
                        "type": [
                            "string",
                            "null"
                        ]
                    },
                    "params": {
                        "type": "array",
                        "items": {
                            "$ref": "#/$defs/Param"
                        }
                    },
                    "file_response": {
                        "type": [
                            "string",
                            "null"
                        ]
                    },
                    "all_col_in_query_endpoint": {
                        "type": [
                            "boolean",
                            "null"
                        ]
                    },
                    "timestamp": {
                        "type": [
                            "string",
                            "null"
                        ],
                        "format": "date-time"
                    },
                    "query_endpoint": {
                        "type": [
                            "boolean",
                            "null"
                        ]
                    },
                    "enable_cache": {
                        "type": [
                            "boolean",
                            "null"
                        ]
                    },
                    "cache_expiration_time_seconds": {
                        "type": [
                            "integer",
                            "null"
                        ]
                    }
                }
            }
        },
        "$schema": "https://json-schema.org/draft/2020-12/schema"
    }
    
    opened by aersam 3
  • Harmonize annotations with python/typeshed#8608

    Harmonize annotations with python/typeshed#8608

    I haven't had time to focus on jsonschema typing much recently, but I want to get things back on track. The first thing to do is to correct any drift between jsonschema and typeshed. I'm going to try to produce a steady stream of very small PRs which get things back in sync.

    This is therefore hopefully the first of a few changes.


    python/typeshed#8608 introduced annotations for create which are not fully reflected here.

    In order to reflect that state into jsonschema, a new module, jsonschema._typing is introduced. The purpose of _typing is to be a singular place for the library to define type aliases and any typing-related utilities which may be needed. This will let us use aliases like _typing.JsonValue in many locations where any valid JSON datatype is accepted. The definitions can be refined over time as necessary.

    Initial definitions in _typing are:

    • Schema (any JSON object)
    • JsonObject (any JSON object)
    • JsonValue (any JSON value, including objects or sequences)

    Schema is just another name for JsonObject. Perhaps it is not needed, but the name may help clarify things to a reader. It is not obvious at present whether or not it is a good or bad idea to notate it as such, but a similar Schema alias is defined in typeshed and seems to be working there to annotate things accurately.

    These types are using Mapping and Sequence rather than dict or list. The rationale is that jsonschema's logic does not dictate that the objects used must be defined in stdlib types or subtypes thereof. For example, a collections.UserDict could be used and should be accepted by the library (UserDict wraps but does not inherit from dict.)


    :books: Documentation preview :books:: https://python-jsonschema--1027.org.readthedocs.build/en/1027/

    opened by sirosen 3
  • Issue with unevaluatedProperties and allOf and arrays

    Issue with unevaluatedProperties and allOf and arrays

    I need to have a schema allowing extra fields only under one specific node (ExtensionProperties). It works well using "additionalProperties": false with simple schemas:

    {
        "$schema": "https://json-schema.org/draft/2019-09/schema#",
        "type": "object",
        "additionalProperties": false,
        "properties": {
            "rootppty": {
                "type": "string"
            },
            "ExtensionProperties": {
                "type": "object"          
            }
        }
    }
    
    

    This data is ok

    {
      "rootppty": "ad",
       "ExtensionProperties": {
          "whatever": "you want"
        }
    }
    

    and this one fails validation as expected

    {
      "rootppty": "ok",
      "other": "fail",
       "ExtensionProperties": {
          "whatever": "you want"
        }
    }
    

    But when I have some allOf, I need to use "unevaluatedProperties": false as explained in the documentation It works well with simple schemas

    {
        "$schema": "https://json-schema.org/draft/2019-09/schema#",
        "type": "object",
        "additionalProperties": false,
        "properties": {
            "rootppty": {
                "type": "string"
            },
            "data": {
              "unevaluatedProperties": false,
              "allOf": [{
                "type": "object",
                "title": "IndividualProperties",
                "properties": {
                  "Nestedppty": {
                    "type": "string"
                  }
                }
              }
             ]
            },
            "ExtensionProperties": {
                "type": "object"          
            }
        }
    }
    

    This data fails the validation as expected (on rootppty2 and Nestedppty2)

    {
      "rootppty": "ok",
      "rootppty2": "fail",
      "data": {
        "Nestedppty": "ok",
        "Nestedppty2": "fail"
      },
       "ExtensionProperties": {
          "whatever": "you want"
        }
    }
    

    But when I am adding array in the allOf part I am facing issues This schema does not fail validation on additional fields in the array

    {
        "$schema": "https://json-schema.org/draft/2019-09/schema#",
        "type": "object",
        "additionalProperties": false,
        "properties": {
            "rootppty": {
                "type": "string"
            },
            "data": {
                "unevaluatedProperties": false,
                "allOf": [{
                        "type": "object",
                        "title": "IndividualProperties",
                        "properties": {
                            "Nestedppty": {
                                "type": "string"
                            },
                            "Nestedarray": {
                                "type": "array",
                                "items": {
                                    "unevaluatedProperties": false,
                                    "type": "object",
                                    "properties": {
                                        "additionalProperties": false,
                                        "nestedarrayInternalpty": {
                                            "type": "string"
                                        }
                                    }
                                }
                            }
                        }
                    }
                ]
            },
            "ExtensionProperties": {
                "type": "object"
            }
        }
    }
    
    

    for example this data should fail validation on nestedarrayInternalpty2

    {
      "rootppty": "ok",
      "data": {
        "Nestedppty": "ok",
        "Nestedarray": [
          {"nestedarrayInternalpty": "ok"},
          {"nestedarrayInternalpty2": "should fail"}
        ]
      },
       "ExtensionProperties": {
          "whatever": "you want"
        }
    }
    

    but it fails also on Nestedppty, which should be ok Am I doing something wrong or is there an issue when several "unevaluatedProperties": false are nested ?

    opened by silversurfer34 0
  • Add some typing to the ``exceptions.py`` module

    Add some typing to the ``exceptions.py`` module

    After getting the go-ahead in https://github.com/python-jsonschema/jsonschema/issues/1017 I thought I would test the waters both in size and scope of potential PRs.

    Feel free to ask me to separate some of the commits into separate PRs. I thought this was quite manageable, especially if you go commit by commit.


    I thought I would start with a fairly self contained module (and a module I interact with quite a lot with at work myself). I think most of the changes are pretty straight forward. The first commit is hardest to review and for now I focused on the attributes that I was most sure about, keeping harder ones for later.

    The second and third commit "fix issues". I understand that these are not actual issues and that through the dynamicness of Python these code paths actually currently work. So: what is the desired action here? Add ignores to tell mypy we know this works? Or add some isinstance checks and attribute definitions to make the code actually type safe. I lean towards the latter but don't want to impose my personal preference on a project I am not involved with until now. I'm more than happy to change those commits to do something differenty!

    Happy reviewing 😄

    Edit: Sorry for all the force pushes, after a helpful comment from @ AlexWaygood in the typeshed repo I found one issue with my initial PR.


    :books: Documentation preview :books:: https://python-jsonschema--1019.org.readthedocs.build/en/1019/

    opened by DanielNoord 3
  • BUG: validator tries to resolve $id although there are no outside references

    BUG: validator tries to resolve $id although there are no outside references

    Looking at the following MCVE:

    import jsonschema
    
    null = None
    
    schema = {
      "$schema": "https://json-schema.org/draft/2020-12/schema",
      "$id": "tag:example.com,2022:test.schema.json",
      # "$id": "worksfinewithoutcolon",
      "$ref": "#/$defs/foo",
    
      "$defs": {
    
        "foo": {
          "properties": {
            "bar": {
              "$ref": "#/$defs/bar"
            }
          }
        },
    
        "bar": { }
      }
    }
    
    instance = {
      "bar": 42
    }
    
    jsonschema.validate(instance, schema)
    

    This raises:

    Full Traceback
    Traceback (most recent call last):
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/validators.py", line 898, in resolve_from_url
        document = self.store[url]
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/_utils.py", line 28, in __getitem__
        return self.store[self.normalize(uri)]
    
    KeyError: ''
    
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/validators.py", line 901, in resolve_from_url
        document = self.resolve_remote(url)
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/validators.py", line 1007, in resolve_remote
        with urlopen(uri) as url:
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/urllib/request.py", line 216, in urlopen
        return opener.open(url, data, timeout)
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/urllib/request.py", line 503, in open
        req = Request(fullurl, data)
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/urllib/request.py", line 322, in __init__
        self.full_url = url
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/urllib/request.py", line 348, in full_url
        self._parse()
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/urllib/request.py", line 377, in _parse
        raise ValueError("unknown url type: %r" % self.full_url)
    
    ValueError: unknown url type: ''
    
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/spyder_kernels/py3compat.py", line 356, in compat_exec
        exec(code, globals, locals)
    
      File "/home/lukas/Desktop/scratch/schemaref.py", line 41, in <module>
        jsonschema.validate(instance, schema, resolver=resolver)
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/validators.py", line 1108, in validate
        error = exceptions.best_match(validator.iter_errors(instance))
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/exceptions.py", line 382, in best_match
        best = next(errors, None)
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/validators.py", line 278, in iter_errors
        for error in errors:
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/_validators.py", line 332, in properties
        yield from validator.descend(
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/validators.py", line 295, in descend
        for error in self.evolve(schema=schema).iter_errors(instance):
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/validators.py", line 278, in iter_errors
        for error in errors:
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/_validators.py", line 298, in ref
        yield from validator.descend(instance, resolved)
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/validators.py", line 295, in descend
        for error in self.evolve(schema=schema).iter_errors(instance):
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/validators.py", line 278, in iter_errors
        for error in errors:
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/_validators.py", line 294, in ref
        scope, resolved = validator.resolver.resolve(ref)
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/validators.py", line 887, in resolve
        return url, self._remote_cache(url)
    
      File "/home/lukas/anaconda3/envs/ifos_test/lib/python3.10/site-packages/jsonschema/validators.py", line 903, in resolve_from_url
        raise exceptions.RefResolutionError(exc)
    
    RefResolutionError: unknown url type: ''
    
    RefResolutionError: unknown url type: ''
    

    According to my reading of the spec, this should validate just fine. Hyperjump also finds these JSONs valid (after removing the # comment line).

    However, jsonschema fails here. It looks like two things are needed for the error to happen:

    • A URI in the "$id" field where jsonschema doesn't know the scheme (or a string that looks like a URI).
    • Nested "$ref" statements.

    According to the spec:

    The $id keyword defines a URI for the schema, and the base URI that other URI references within the schema are resolved against.

    jsonschema validates the file just fine if the "$id" doesn't contain a colon. I don't even understand why it tries to resolve the "$id".

    Related: #313

    opened by joooeey 2
  • Consider an API which collects validation errors and raises an exception group

    Consider an API which collects validation errors and raises an exception group

    Python 3.11 now supports exception groups for grouping together multiple (simultaneous, unrelated) exceptions.

    This seems to suit us -- right now we have:

    • Validator.iter_errors, aimed at returning (not raising) all errors
    • Validator.is_valid, aimed at returning no errors and indicating via a boolean whether things are OK
    • Validator.validate, aimed at raising 1 single exception (the first encountered one)

    Another API where we raise all exceptions iter_errors would have returned seems like it may fit the picture.

    Enhancement 
    opened by Julian 0
Releases(v4.17.3)
  • v4.17.3(Nov 29, 2022)

    • Fix instantiating validators with cached refs to boolean schemas rather than objects (#1018).
    • Empty strings are not valid relative JSON Pointers (aren't valid under the RJP format).
    • Durations without (trailing) units are not valid durations (aren't valid under the duration format). This involves changing the dependency used for validating durations (from isoduration to isodate).

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.17.2...v4.17.3

    Source code(tar.gz)
    Source code(zip)
  • v4.17.1(Nov 22, 2022)

    • The error message when using unevaluatedProperties with a non-trivial schema value (i.e. something other than false) has been improved (#996).

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.17.0...v4.17.1

    Source code(tar.gz)
    Source code(zip)
  • v4.17.0(Nov 1, 2022)

    • The check_schema method on jsonschema.protocols.Validator instances now enables format validation by default when run. This can catch some additional invalid schemas (e.g. containing invalid regular expressions) where the issue is indeed uncovered by validating against the metaschema with format validation enabled as an assertion.
    • The jsonschema CLI (along with jsonschema.cli the module) are now deprecated. Use check-jsonschema instead, which can be installed via pip install check-jsonschema and found here.
    • Make ErrorTree have a more grammatically correct repr.

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.16.0...v4.17.0

    Source code(tar.gz)
    Source code(zip)
  • v4.16.0(Sep 9, 2022)

    • Improve the base URI behavior when resolving a $ref to a resolution URI which is different from the resolved schema's declared $id.
    • Accessing jsonschema.draftN_format_checker is deprecated. Instead, if you want access to the format checker itself, it is exposed as jsonschema.validators.DraftNValidator.FORMAT_CHECKER on any jsonschema.protocols.Validator.

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.15.0...v4.16.0

    Source code(tar.gz)
    Source code(zip)
  • v4.15.0(Aug 31, 2022)

    What's Changed

    • Enable dedicated API documentation page(s) by @Julian in https://github.com/python-jsonschema/jsonschema/pull/989

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.14.0...v4.15.0

    Source code(tar.gz)
    Source code(zip)
  • v4.14.0(Aug 21, 2022)

    • FormatChecker.cls_checks is deprecated. Use FormatChecker.checks on an instance of FormatChecker instead.
    • unevaluatedItems has been fixed for draft 2019. It's nonetheless discouraged to use draft 2019 for any schemas, new or old.
    • Fix a number of minor annotation issues in protocols.Validator

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.13.0...v4.14.0

    Source code(tar.gz)
    Source code(zip)
  • v4.13.0(Aug 19, 2022)

    • Add support for creating validator classes whose metaschema uses a different dialect than its schemas. In other words, they may use draft2020-12 to define which schemas are valid, but the schemas themselves use draft7 (or a custom dialect, etc.) to define which instances are valid. Doing this is likely not something most users, even metaschema authors, may need, but occasionally will be useful for advanced use cases.

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.12.1...v4.13.0

    Source code(tar.gz)
    Source code(zip)
  • v4.12.1(Aug 18, 2022)

    What's Changed

    • Use rST markers in README by @hynek in https://github.com/python-jsonschema/jsonschema/pull/987

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.12.0...v4.12.1

    Source code(tar.gz)
    Source code(zip)
  • v4.12.0(Aug 18, 2022)

    • Warn at runtime when subclassing validator classes. Doing so was not intended to be public API, though it seems some downstream libraries do so. A future version will make this an error, as it is brittle and better served by composing validator objects instead. Feel free to reach out if there are any cases where changing existing code seems difficult and I can try to provide guidance.

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.11.0...v4.12.0

    Source code(tar.gz)
    Source code(zip)
  • v4.11.0(Aug 18, 2022)

    What's Changed

    • jsonschema deserves a ✨fancy✨ readme by @hynek in https://github.com/python-jsonschema/jsonschema/pull/983

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.10.3...v4.11.0

    Source code(tar.gz)
    Source code(zip)
  • v4.10.3(Aug 18, 2022)

    • jsonschema.validators.validator_for now properly uses the explicitly provided default validator even if the $schema URI is not found.

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.10.2...v4.10.3

    Source code(tar.gz)
    Source code(zip)
  • v4.10.2(Aug 17, 2022)

    • Fix a second place where subclasses may have added attrs attributes (#982).

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.10.1...v4.10.2

    Source code(tar.gz)
    Source code(zip)
  • v4.10.1(Aug 17, 2022)

    • Fix Validator.evolve (and APIs like iter_errors which call it) for cases where the validator class has been subclassed. Doing so wasn't intended to be public API, but given it didn't warn or raise an error it's of course understandable. The next release however will make it warn (and a future one will make it error). If you need help migrating usage of inheriting from a validator class feel free to open a discussion and I'll try to give some guidance (#982).

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.10.0...v4.10.1

    Source code(tar.gz)
    Source code(zip)
  • v4.10.0(Aug 16, 2022)

    • Add support for referencing schemas with $ref across different versions of the specification than the referrer's

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.9.1...v4.10.0

    Source code(tar.gz)
    Source code(zip)
  • v4.9.1(Aug 3, 2022)

    • Update some documentation examples to use newer validator releases in their sample code.

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.9.0...v4.9.1

    Source code(tar.gz)
    Source code(zip)
  • v4.9.0(Jul 31, 2022)

    • Fix relative $ref resolution when the base URI is a URN or other scheme (#544).
    • pkgutil.resolve_name is now used to retrieve validators provided on the command line. This function is only available on 3.9+, so 3.7 and 3.8 (which are still supported) now rely on the pkgutil_resolve_name <https://pypi.org/project/pkgutil_resolve_name/>_ backport package. Note however that the CLI itself is due to be deprecated shortly in favor of check-jsonschema <https://github.com/python-jsonschema/check-jsonschema>_.

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.8.0...v4.9.0

    Source code(tar.gz)
    Source code(zip)
  • v4.8.0(Jul 28, 2022)

    • best_match no longer traverses into anyOf and oneOf when all of the errors within them seem equally applicable. This should lead to clearer error messages in some cases where no branches were matched.

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.7.2...v4.8.0

    Source code(tar.gz)
    Source code(zip)
  • v4.7.2(Jul 12, 2022)

    • Also have best_match handle cases where the type validator is an array.

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.7.1...v4.7.2

    Source code(tar.gz)
    Source code(zip)
  • v4.7.1(Jul 11, 2022)

  • v4.7.0(Jul 11, 2022)

    What's Changed

    • Enhance best match to prefer errors from matching types. by @Julian in https://github.com/python-jsonschema/jsonschema/pull/972

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.6.2...v4.7.0

    Source code(tar.gz)
    Source code(zip)
  • v4.6.2(Jul 7, 2022)

    What's Changed

    • docs: Fix a few typos by @timgates42 in https://github.com/python-jsonschema/jsonschema/pull/969

    New Contributors

    • @timgates42 made their first contribution in https://github.com/python-jsonschema/jsonschema/pull/969

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.6.1...v4.6.2

    Source code(tar.gz)
    Source code(zip)
  • v4.6.1(Jun 28, 2022)

    What's Changed

    • Type annotate format checker methods by @sirosen in https://github.com/python-jsonschema/jsonschema/pull/958
    • Fix fuzzer to include instrumentation by @DavidKorczynski in https://github.com/python-jsonschema/jsonschema/pull/965
    • [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci in https://github.com/python-jsonschema/jsonschema/pull/967

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.6.0...v4.6.1

    Source code(tar.gz)
    Source code(zip)
  • v4.6.0(Jun 1, 2022)

    What's Changed

    • Add package_url for changelog by @fhightower in https://github.com/python-jsonschema/jsonschema/pull/950
    • Only validate unevaluated properties/items on applicable types by @EpicWink in https://github.com/python-jsonschema/jsonschema/pull/949
    • Add v4.5.1 to changelog by @sirosen in https://github.com/python-jsonschema/jsonschema/pull/956
    • Modernize the packaging setup via PEP 621 and Hatch. by @Julian in https://github.com/python-jsonschema/jsonschema/pull/957

    New Contributors

    • @fhightower made their first contribution in https://github.com/python-jsonschema/jsonschema/pull/950
    • @EpicWink made their first contribution in https://github.com/python-jsonschema/jsonschema/pull/949

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.5.1...v4.6.0

    Source code(tar.gz)
    Source code(zip)
  • v4.5.1(May 5, 2022)

  • v4.5.0(May 5, 2022)

    What's Changed

    • Extend dynamicRef keyword by @nezhar in https://github.com/python-jsonschema/jsonschema/pull/886
    • Add FORMAT_CHECKER attribute for Validator by @TiborVoelcker in https://github.com/python-jsonschema/jsonschema/pull/905
    • Remove stray double-quote by @lurch in https://github.com/python-jsonschema/jsonschema/pull/926
    • Ensure proper sorting of list in error message by @ssbarnea in https://github.com/python-jsonschema/jsonschema/pull/940

    New Contributors

    • @TiborVoelcker made their first contribution in https://github.com/python-jsonschema/jsonschema/pull/905
    • @lurch made their first contribution in https://github.com/python-jsonschema/jsonschema/pull/926
    • @ssbarnea made their first contribution in https://github.com/python-jsonschema/jsonschema/pull/940

    Full Changelog: https://github.com/python-jsonschema/jsonschema/compare/v4.4.0...v4.5.0

    Source code(tar.gz)
    Source code(zip)
  • v4.4.0(Jan 12, 2022)

    What's Changed

    • Setup mypy in tox -e typing and get it to pass by @sirosen in https://github.com/Julian/jsonschema/pull/892

    Full Changelog: https://github.com/Julian/jsonschema/compare/v4.3.3...v4.4.0

    Source code(tar.gz)
    Source code(zip)
  • v4.3.3(Jan 1, 2022)

    What's Changed

    • [pre-commit.ci] pre-commit autoupdate by @pre-commit-ci in https://github.com/Julian/jsonschema/pull/897
    • Move warnings to user context by @Kojoley in https://github.com/Julian/jsonschema/pull/899

    New Contributors

    • @Kojoley made their first contribution in https://github.com/Julian/jsonschema/pull/899

    Full Changelog: https://github.com/Julian/jsonschema/compare/v4.3.2...v4.3.3

    Source code(tar.gz)
    Source code(zip)
  • v4.3.2(Dec 20, 2021)

    What's Changed

    • perf: Cache subschemas by @Stranger6667 in https://github.com/Julian/jsonschema/pull/896

    Full Changelog: https://github.com/Julian/jsonschema/compare/v4.3.1...v4.3.2

    Source code(tar.gz)
    Source code(zip)
  • v4.3.1(Dec 17, 2021)

    What's Changed

    • perf: Cache reference lookups for subschemas by @Stranger6667 in https://github.com/Julian/jsonschema/pull/894

    Full Changelog: https://github.com/Julian/jsonschema/compare/v4.3.0...v4.3.1

    Source code(tar.gz)
    Source code(zip)
  • v4.3.0(Dec 15, 2021)

    What's Changed

    • perf: Undesired fallback to brute force container uniqueness check on certain input types by @Stranger6667 in https://github.com/Julian/jsonschema/pull/893
    • Add jsonschema.protocols.IValidator by @sirosen in https://github.com/Julian/jsonschema/pull/890

    New Contributors

    • @Stranger6667 made their first contribution in https://github.com/Julian/jsonschema/pull/893
    • @sirosen made their first contribution in https://github.com/Julian/jsonschema/pull/890

    Full Changelog: https://github.com/Julian/jsonschema/compare/v4.2.1...v4.3.0

    Source code(tar.gz)
    Source code(zip)
Owner
Julian Berman
Lover of things. Climber of molehills. Seeking friends for the end of the world.
Julian Berman
With Holoviews, your data visualizes itself.

HoloViews Stop plotting your data - annotate your data and let it visualize itself. HoloViews is an open-source Python library designed to make data a

HoloViz 2.3k Jan 02, 2023
Jupyter notebook and datasets from the pandas Q&A video series

Python pandas Q&A video series Read about the series, and view all of the videos on one page: Easier data analysis in Python with pandas. Jupyter Note

Kevin Markham 2k Jan 05, 2023
2021 grafana arbitrary file read

2021_grafana_arbitrary_file_read base on pocsuite3 try 40 default plugins of grafana alertlist annolist barchart cloudwatch dashlist elasticsearch gra

ATpiu 5 Nov 09, 2022
Colormaps for astronomers

cmastro: colormaps for astronomers 🔭 This package contains custom colormaps that have been used in various astronomical applications, similar to cmoc

Adrian Price-Whelan 12 Oct 11, 2022
Homework 2: Matplotlib and Data Visualization

Homework 2: Matplotlib and Data Visualization Overview These data visualizations were created for my introductory computer science course using Python

Sophia Huang 12 Oct 20, 2022
3D Vision functions with end-to-end support for deep learning developers, written in Ivy.

Ivy vision focuses predominantly on 3D vision, with functions for camera geometry, image projections, co-ordinate frame transformations, forward warping, inverse warping, optical flow, depth triangul

Ivy 61 Dec 29, 2022
A GUI for Pandas DataFrames

About Demo Installation Usage Features More Info About PandasGUI is a GUI for viewing, plotting and analyzing Pandas DataFrames. Demo Installation Ins

Adam Rose 2.8k Dec 24, 2022
Frbmclust - Clusterize FRB profiles using hierarchical clustering, plot corresponding parameters distributions

frbmclust Getting Started Clusterize FRB profiles using hierarchical clustering,

3 May 06, 2022
ICS-Visualizer is an interactive Industrial Control Systems (ICS) network graph that contains up-to-date ICS metadata

ICS-Visualizer is an interactive Industrial Control Systems (ICS) network graph that contains up-to-date ICS metadata (Name, company, port, user manua

QeeqBox 2 Dec 13, 2021
Painlessly create beautiful matplotlib plots.

Announcement Thank you to everyone who has used prettyplotlib and made it what it is today! Unfortunately, I no longer have the bandwidth to maintain

Olga Botvinnik 1.6k Jan 06, 2023
Type-safe YAML parser and validator.

StrictYAML StrictYAML is a type-safe YAML parser that parses and validates a restricted subset of the YAML specification. Priorities: Beautiful API Re

Colm O'Connor 1.2k Jan 04, 2023
Jupyter Notebook extension leveraging pandas DataFrames by integrating DataTables and ChartJS.

Jupyter DataTables Jupyter Notebook extension to leverage pandas DataFrames by integrating DataTables JS. About Data scientists and in fact many devel

Marek Čermák 142 Dec 28, 2022
Using SQLite within Python to create database and analyze Starcraft 2 units data (Pandas also used)

SQLite python Starcraft 2 English This project shows the usage of SQLite with python. To create, modify and communicate with the SQLite database from

1 Dec 30, 2021
WebApp served by OAK PoE device to visualize various streams, metadata and AI results

DepthAI PoE WebApp | Bootstrap 4 & Vue.js SPA Dashboard Based on dashmin (https:

Luxonis 6 Apr 09, 2022
Small binja plugin to import header file to types

binja-import-header (v1.0.0) Author: matteyeux Import header file to Binary Ninja types view Description: Binary Ninja plugin to import types from C h

matteyeux 15 Dec 10, 2022
CLAHE Contrast Limited Adaptive Histogram Equalization

A simple code to process images using contrast limited adaptive histogram equalization. Image processing is becoming a major part of data processig.

Happy N. Monday 4 May 18, 2022
A simple interpreted language for creating basic mathematical graphs.

graphr Introduction graphr is a small language written to create basic mathematical graphs. It is an interpreted language written in python and essent

2 Dec 26, 2021
This is a small program that prints a user friendly, visual representation, of your current bsp tree

bspcq, q for query A bspc analyzer (utility for bspwm) This is a small program that prints a user friendly, visual representation, of your current bsp

nedia 9 Apr 24, 2022
Epagneul is a tool to visualize and investigate windows event logs

epagneul Epagneul is a tool to visualize and investigate windows event logs. Dep

jurelou 190 Dec 13, 2022
Movie recommendation using RASA, TigerGraph

Demo run: The below video will highlight the runtime of this setup and some sample real-time conversations using the power of RASA + TigerGraph, Steps

Sudha Vijayakumar 3 Sep 10, 2022