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
Schema validation for Xarray objects

xarray-schema Schema validation for Xarray installation This package is in the early stages of development. Install it from source: pip install git+gi

carbonplan 22 Oct 31, 2022
Generate "Jupiter" plots for circular genomes

jupiter Generate "Jupiter" plots for circular genomes Description Python scripts to generate plots from ViennaRNA output. Written in "pidgin" python w

Robert Edgar 2 Nov 29, 2021
Pglive - Pglive package adds support for thread-safe live plotting to pyqtgraph

Live pyqtgraph plot Pglive package adds support for thread-safe live plotting to

Martin Domaracký 15 Dec 10, 2022
Python & Julia port of codes in excellent R books

X4DS This repo is a collection of Python & Julia port of codes in the following excellent R books: An Introduction to Statistical Learning (ISLR) Stat

Gitony 5 Jun 21, 2022
This repository contains a streaming Dataflow pipeline written in Python with Apache Beam, reading data from PubSub.

Sample streaming Dataflow pipeline written in Python This repository contains a streaming Dataflow pipeline written in Python with Apache Beam, readin

Israel Herraiz 9 Mar 18, 2022
Python scripts for plotting audiograms and related data from Interacoustics Equinox audiometer and Otoaccess software.

audiometry Python scripts for plotting audiograms and related data from Interacoustics Equinox 2.0 audiometer and Otoaccess software. Maybe similar sc

Hamilton Lab at UT Austin 2 Jun 15, 2022
Statistical data visualization using matplotlib

seaborn: statistical data visualization Seaborn is a Python visualization library based on matplotlib. It provides a high-level interface for drawing

Michael Waskom 10.2k Dec 30, 2022
This is a place where I'm playing around with pandas to analyze data in a csv/excel file.

pandas-csv-excel-analysis This is a place where I'm playing around with pandas to analyze data in a csv/excel file. 0-start A very simple cheat sheet

Chuqin 3 Oct 05, 2022
Data visualization using matplotlib

Data visualization using matplotlib project instructions Top 5 Most Common Coffee Origins In this visualization I used data from Ankur Chavda on Kaggl

13 Oct 27, 2021
649 Pokémon palettes as CSVs, with a Python lib to turn names/IDs into palettes, or MatPlotLib compatible ListedColormaps.

PokePalette 649 Pokémon, broken down into CSVs of their RGB colour palettes. Complete with a Python library to convert names or Pokédex IDs into eithe

11 Dec 05, 2022
Apache Superset is a Data Visualization and Data Exploration Platform

Apache Superset is a Data Visualization and Data Exploration Platform

The Apache Software Foundation 49.9k Jan 02, 2023
Arras.io Highest Scores Over Time Bar Chart Race

Arras.io Highest Scores Over Time Bar Chart Race This repo contains a python script (make_racing_bar_chart.py) that can generate a csv file which can

Road 2 Jan 16, 2022
Flipper Zero documentation repo

Flipper Zero Docs Participation To fix a bug or add something new to this repository, you need to open a pull-request. Also, on every page of the site

Flipper Zero (All Repositories will be public soon) 114 Dec 30, 2022
Drag’n’drop Pivot Tables and Charts for Jupyter/IPython Notebook, care of PivotTable.js

pivottablejs: the Python module Drag’n’drop Pivot Tables and Charts for Jupyter/IPython Notebook, care of PivotTable.js Installation pip install pivot

Nicolas Kruchten 512 Dec 26, 2022
Write python locally, execute SQL in your data warehouse

RasgoQL Write python locally, execute SQL in your data warehouse ≪ Read the Docs · Join Our Slack » RasgoQL is a Python package that enables you to ea

Rasgo 265 Nov 21, 2022
A Simple Flask-Plotly Example for NTU 110-1 DSSI Class

A Simple Flask-Plotly Example for NTU 110-1 DSSI Class Live Demo Prerequisites We will use Flask and Ploty to build a Flask application. If you haven'

Ting Ni Wu 1 Dec 11, 2021
Param: Make your Python code clearer and more reliable by declaring Parameters

Param Param is a library providing Parameters: Python attributes extended to have features such as type and range checking, dynamically generated valu

HoloViz 304 Jan 07, 2023
A command line tool for visualizing CSV/spreadsheet-like data

PerfPlotter Read data from CSV files using pandas and generate interactive plots using bokeh, which can then be embedded into HTML pages and served by

Gino Mempin 0 Jun 25, 2022
Visualization Library

CamViz Overview // Installation // Demos // License Overview CamViz is a visualization library developed by the TRI-ML team with the goal of providing

Toyota Research Institute - Machine Learning 67 Nov 24, 2022
An interactive dashboard built with python that enables you to visualise how rent prices differ across Sweden.

sweden-rent-dashboard An interactive dashboard built with python that enables you to visualise how rent prices differ across Sweden. The dashboard/web

Rory Crean 5 Dec 19, 2021