Questions tagged [python-jsonschema]
126 questions
2
votes
2 answers
ValidationError assertion not working when pytest shows the same values
I'm writing a unit test whereby I want to assert that the error I get:
is equal too
assert ValidationError(message="'a list' is not of type 'array'")
I'm using a simple assertion:
assert actual…

Blue Moon
- 4,421
- 20
- 52
- 91
2
votes
1 answer
Loading Valid Values from Another JSON File
I would like to create a JSON schema that defines two entities: region and country.
The JSON schema for country is as follows:
{
"$id":"https://example.com/arrays.schema.json",
"$schema":"http://json-schema.org/draft-07/schema#",
…

jwa
- 3,239
- 2
- 23
- 54
2
votes
1 answer
How to validate a list of dictionaries using jsonschema with Python
I have a list of dictionaries like this:
list_of_dictionaries = [{'key1': True}, {'key2': 0.2}]
And I want to validate it using jsonschema package.
I created a schema like this:
schema = {
"type": "array",
"items": {
"type":…

Claudio Ciccarone
- 65
- 1
- 9
2
votes
1 answer
Python tools/libraries to validate a JSON schema
Are there any python libraries or tools that check if a JSON schema is valid?
I do not want to validate an instance against a JSON schema, but I would like to check if the JSON schema itself is valid or not. For example, if all the required fields…

Marc
- 588
- 2
- 15
2
votes
0 answers
jsonschema - python - How to validate a schema containing a ref
I have been trying so hard to figure out how to get a schema that is nested in a definition with a $ref. If I hard code the jsonschema object I have no problems whatsoever, however I need to use a nested schema and I don't know what schema= in…

Gabriel Clark
- 21
- 3
2
votes
3 answers
python jsonschema use pattern on list items not working
I want to use json schema in order to validate something like this:
{
"function_mapper": {
"critical": [
"DataContentValidation.get_multiple_types_columns",
"DataContentValidation.get_invalid_session_ids"
],
"warning": [
…

Ema Il
- 405
- 1
- 5
- 14
2
votes
0 answers
In jsonschema, how do you use the value of a property in one object to check a specific property in another object
I would like to check the following structure:
foo = {
"things": {
"bar": {
"thing-definition-key": "baz",
...
}
},
"thing-definitions": {
…

Adam
- 21
- 2
2
votes
1 answer
If condition with a relative ref using JSON schema draft 7
I would like to use json schema to combine relative JSON pointer references, with a $ref schema, when I am introducing a conditional if / then statement.
In this case I would like to require that:
If system = Phone then require usePhone element
If…

redsky
- 67
- 6
2
votes
1 answer
Failed to find package metadata for jsonschema
I am fairly new to this. I installed jsonschema and importlib_metadata manually and copied it to the folder where I was doing synthesis using make syn i.e., vlsi folder in my case.
It terminates with this error:…

Kiran
- 43
- 8
2
votes
1 answer
JSON schema: Property value must be equal to parent key
According to JSON-Schema 7.0 String section, I can use a "relative-json-pointer" to make sure that a property value is an exact match of a parent key.
In the examples section (5.1) of Relative JSON Pointers, it shows that "going up one level" and…

dotnetCarpenter
- 10,019
- 6
- 32
- 54
2
votes
0 answers
Setting defaults when validating a jsonschema with anyOf keyword
I'd like to make use of the defaults that are defined within my schema. I found that there is already an example within the python-jsonschema faq: https://python-jsonschema.readthedocs.io/en/stable/faq/
The example extends the default validator for…

Tim Keller
- 389
- 1
- 12
2
votes
1 answer
Is there a way to raise an error for any additional key present in JSON if I am using the if-else condition of JSON Schema?
I have a use case where I want to check the keys present in JSON, depending on the value of a different key.
Example JSON-1:
{
"key_name" : "value1",
"foo" : "random_value1"
}
Example JSON-2:
{
"key_name" : "value2",
"bar" :…

Himani Garg
- 93
- 8
2
votes
1 answer
unknown url type with python jsonschema for referenced path
I have multiple large json-schema files. There are properties which are common for many schema files.
To remove redundancy between the common schema definitions, separated those in separated schema files and using $ref to reference to the individual…

Anuj TBE
- 9,198
- 27
- 136
- 285
2
votes
1 answer
jsonschema - oneOf keyword behaves unexpectedly
I'm trying to validate a json payload in Python, using jsonschema 3.0.1, that roughly looks like that (simplified to the troublesome part):
{
"request": {
"topic": {
"param1": "bleep beep topic",
"param2": "bloop…

mkierc
- 1,193
- 2
- 15
- 28
2
votes
2 answers
JSON Schema conditional required if and only if a specific key exists in nested object
My question for jsonschema is twofold:
Given
{
"foo": {"ar": {"a": "r"}},
"bar": ""
}
How do I check if the key "ar" exists inside of "foo"?
And only if "ar" exists inside of "foo", how do I make it so that "bar" must exists inside the given…

Flair
- 2,609
- 1
- 29
- 41