🌐
jsonschema
python-jsonschema.readthedocs.io › en › latest › validate
Schema Validation - jsonschema 4.26.1.dev25+gad0a1b301 documentation
Some formats require additional dependencies to be installed. The easiest way to ensure you have what is needed is to install jsonschema using the format or format-nongpl extras.
🌐
Built In
builtin.com › software-engineering-perspectives › python-json-schema
How to Use JSON Schema to Validate JSON Documents in Python | Built In
Incorrect data types or missing some required fields will trigger the ValidationError. However, it should be noted that by default additional fields are allowed, which may or may not be what you want. If you want a strict schema and only allow fields that are defined by the properties keyword, you can specify the additionalProperties to be False: from jsonschema import validate schema = { "type": "object", "properties": { "name": {"type": "string"}, "age": {"type": "number"}, }, "required": ["name"], "additionalProperties": False } validate(instance={"name": "John", "age": 30, "job": "Engineer"}, schema=schema) # ValidationError: Additional properties are not allowed ('job' was unexpected)
🌐
jsonschema
python-jsonschema.readthedocs.io › en › stable › validate
Schema Validation - jsonschema 4.26.0 documentation
Some formats require additional dependencies to be installed. The easiest way to ensure you have what is needed is to install jsonschema using the format or format-nongpl extras.
🌐
jsonschema
python-jsonschema.readthedocs.io
jsonschema 4.26.0 documentation
PyPI version Supported Python versions Build status ReadTheDocs status pre-commit.ci status Zenodo DOI jsonschema is an implementation of the JSON Schema specification for Python. It can also be us...
🌐
PyPI
pypi.org › project › jsonschema
jsonschema · PyPI
An implementation of JSON Schema validation for Python
      » pip install jsonschema
    
Published   Jan 07, 2026
Version   4.26.0
🌐
JSON Schema
json-schema.org › understanding-json-schema › reference › object
JSON Schema - object
By default, leaving out properties is valid. See Required Properties.
🌐
jsonschema
python-jsonschema.readthedocs.io › en › latest › faq
Frequently Asked Questions - jsonschema 4.26.1.dev15+gcbaf0f8fe documentation
The behavior of this library is therefore similarly not defined when presented with Python objects of this form, which could never have come from JSON. In such cases one is recommended to first pre-process the data such that the resulting behavior is well-defined. In the previous example, if the desired behavior is to transparently coerce numeric properties to strings, as Javascript might, then do the conversion explicitly before passing data to this library. The basic answer is that the specification does not require that default actually do anything.
🌐
jsonschema
python-jsonschema.readthedocs.io › en › stable › faq
Frequently Asked Questions - jsonschema 4.26.0 documentation
The behavior of this library is therefore similarly not defined when presented with Python objects of this form, which could never have come from JSON. In such cases one is recommended to first pre-process the data such that the resulting behavior is well-defined. In the previous example, if the desired behavior is to transparently coerce numeric properties to strings, as Javascript might, then do the conversion explicitly before passing data to this library. The basic answer is that the specification does not require that default actually do anything.
🌐
Read the Docs
app.readthedocs.org › projects › python-jsonschema › downloads › pdf › latest pdf
jsonschema Release 4.26.1.dev25+gad0a1b301 Julian Berman Mar 02, 2026
The JSON Schema specification recommends (but does not require) that implementations use ECMA 262 regular ... Given that there is no current library in Python capable of supporting the ECMA 262 dialect, the regex format will
🌐
Donofden
donofden.com › blog › 2020 › 03 › 15 › How-to-Validate-JSON-Schema-using-Python
How to Validate JSON Schema using Python
import json import jsonschema from jsonschema import validate def get_schema(): """This function loads the given schema available""" with open('user_schema.json', 'r') as file: schema = json.load(file) return schema def validate_json(json_data): """REF: https://json-schema.org/ """ # Describe what kind of json you expect. execute_api_schema = get_schema() try: validate(instance=json_data, schema=execute_api_schema) except jsonschema.exceptions.ValidationError as err: print(err) err = "Given JSON data is InValid" return False, err message = "Given JSON data is Valid" return True, message # Convert json to python object.
Find elsewhere
Top answer
1 of 4
28

I got it to work using this validator by nesting the part of the schema for the array elements inside a object with the name items. The schema now has two nested items fields, but that is because one is a keyword in JSONSchema and the other because your JSON actually has a field called items

JSONSchema:

{
   "type":"object",
   "properties":{
      "items":{
         "type":"array",
         "items":{
            "properties":{
               "item_id":{
                  "type":"number"
               },
               "quantity":{
                  "type":"number"
               },
               "price":{
                  "type":"number"
               },
               "title":{
                  "type":"string"
               },
               "description":{
                  "type":"string"
               }
            },
            "required":[
               "item_id",
               "quantity",
               "price",
               "title",
               "description"
            ],
            "additionalProperties":false
         }
      }
   }
}

JSON:

{
   "items":[
      {
         "item_id":1,
         "quantity":3,
         "price":30,
         "title":"item1 new name"
      },
      {
         "item_id":1,
         "quantity":16,
         "price":30,
         "title":"Test Two"
      }
   ]
}

Output with two errors about missing description fields:

Copy[ {
  "level" : "error",
  "schema" : {
    "loadingURI" : "#",
    "pointer" : "/properties/items/items"
  },
  "instance" : {
    "pointer" : "/items/0"
  },
  "domain" : "validation",
  "keyword" : "required",
  "message" : "missing required property(ies)",
  "required" : [ "description", "item_id", "price", "quantity", "title" ],
  "missing" : [ "description" ]
}, {
  "level" : "error",
  "schema" : {
    "loadingURI" : "#",
    "pointer" : "/properties/items/items"
  },
  "instance" : {
    "pointer" : "/items/1"
  },
  "domain" : "validation",
  "keyword" : "required",
  "message" : "missing required property(ies)",
  "required" : [ "description", "item_id", "price", "quantity", "title" ],
  "missing" : [ "description" ]
} ]

Try pasting the above into here to see the same output generated.

2 of 4
10

I realize this is an old thread, but since this question is linked from jsonschema.net, I thought it might be worth chiming in...

The problem with your original example is that you're declaring "properties" for an "array" type, rather than declaring "items" for the array, and then declaring an "object" type (with "properties") that populates the array. Here's a revised version of the original schema snippet:

"items": {
    "type": "array",
    "items": {
        "type": "object",
        "properties": {
            "item_id": {"type" : "number"},
            "quantity": {"type": "number"},
            "price": {"type" : "decimal"},
            "title": {"type": "string"},
            "description": {"type": "string"}
        },
        "required": ["item_id","quantity","price","title","description"],
        "additionalProperties" : false
    }
}

I would recommend against using the term "items" for the name of the array, to avoid confusion, but there's nothing stopping you from doing that...

🌐
Pydantic
docs.pydantic.dev › latest › concepts › json_schema
JSON Schema - Pydantic Validation
{ "$defs": { "Cat": { "properties": { "name": { "title": "Name", "type": "string" }, "color": { "title": "Color", "type": "string" } }, "required": [ "name", "color" ], "title": "Cat", "type": "object" }, "Dog": { "properties": { "name": { "title": "Name", "type": "string" }, "breed": { "title": "Breed", "type": "string" } }, "required": [ "name", "breed" ], "title": "Dog", "type": "object" } }, "anyOf": [ { "$ref": "#/$defs/Cat" }, { "$ref": "#/$defs/Dog" } ] } Specify the mode of JSON schema generation via the mode parameter in the model_json_schema and TypeAdapter.json_schema methods. By default, the mode is set to 'validation', which produces a JSON schema corresponding to the model's validation schema. The JsonSchemaMode is a type alias that represents the available options for the mode parameter:
🌐
LinkedIn
linkedin.com › pulse › mastering-json-schema-validation-python-developers-guide-singh-ebffc
Mastering JSON Schema Validation with Python: A Developer’s Guide
February 16, 2024 - Validating nested structures requires a detailed approach. Here’s how you might validate a nested object: from jsonschema import validate schema = { "type": "object", "properties": { "employee": { "type": "object", "properties": { "id": {"type": "number"}, "name": {"type": "string"} }, "required": ["id", "name"] } }, } data = {"employee": {"id": 123, "name": "Jane Doe"}} validate(instance=data, schema=schema)
🌐
TechTutorialsX
techtutorialsx.com › 2020 › 03 › 05 › python-json-schema-validation
Python: JSON schema validation – techtutorialsx
March 5, 2020 - from jsonschema import validate, ValidationError, SchemaError schema = { "type" : "object", "properties" : { "name" : {"type" : "string"}, "age" : { "type" : "number", } }, "required": ["age","name"] } validJson = {"name" : "Eggs", "age" : 10} invalidJson = {"name" : "Eggs", "age":"string"} validate(validJson, schema) try: validate(invalidJson, schema) except SchemaError as e: print("There is an error with the schema") except ValidationError as e: print(e) print("---------") print(e.absolute_path) print("---------") print(e.absolute_schema_path)
🌐
GeeksforGeeks
geeksforgeeks.org › python › introduction-to-python-jsonschema
Introduction to Python jsonschema - GeeksforGeeks
July 23, 2025 - To validate JSON data using jsonschema, we first define a schema and then use the validate function from the jsonschema library. Here's a simple example: This code defines a schema requiring an object with name (string) and age (integer).
🌐
GitHub
github.com › cwacek › python-jsonschema-objects
GitHub - cwacek/python-jsonschema-objects: Automatic Python binding generation from JSON Schemas · GitHub
{ "title": "Example Schema", "type": "object", "properties": { "firstName": { "type": "string" }, "lastName": { "type": "string" }, "age": { "description": "Age in years", "type": "integer", "minimum": 0 }, "dogs": { "type": "array", "items": {"type": "string"}, "maxItems": 4 }, "address": { "type": "object", "properties": { "street": {"type": "string"}, "city": {"type": "string"}, "state": {"type": "string"} }, "required":["street", "city"] }, "gender": { "type": "string", "enum": ["male", "female"] }, "deceased": { "enum": ["yes", "no", 1, 0, "true", "false"] } }, "required": ["firstName", "
Starred by 373 users
Forked by 90 users
Languages   Python
🌐
Towards Data Science
towardsdatascience.com › home › latest › how to use json schema to validate json documents in python
How to Use JSON Schema to Validate JSON Documents in Python | Towards Data Science
March 5, 2025 - This JSON schema specifies that the target JSON is an object with two properties (which are also commonly referred to as keys/fields and will be used accordingly when appropriate), and the name property is required.
🌐
GitHub
github.com › pydantic › pydantic › issues › 8714
valid Pydantic model with fields having `required` attribute generates invalid JSON schema · Issue #8714 · pydantic/pydantic
February 2, 2024 - import pydantic import jsonschema class ValidModel(pydantic.BaseModel): f: int = pydantic.Field(...) class InvalidModel(pydantic.BaseModel): f: int = pydantic.Field(..., required=True) print(pydantic.version.version_info()) print(ValidModel.schema_json(indent=2)) print(InvalidModel.schema_json(indent=2)) try: jsonschema.validate(InvalidModel(f=1).dict(), InvalidModel.schema()) except jsonschema.exceptions.SchemaError as e: print(e) reproduced both with Pydantic 1.x and Pydantic 2.x · pydantic version: 1.9.0 pydantic compiled: True install path: /home/kostunin/.local/lib/python3.10/site-packages/pydantic python version: 3.10.12 (main, Nov 20 2023, 15:14:05) [GCC 11.4.0] platform: Linux-5.14.0-1036-oem-x86_64-with-glibc2.35 optional deps.
Author   kostunin
🌐
Horejsek
horejsek.github.io › python-fastjsonschema
Fast JSON schema for Python — fastjsonschema documentation
Support only for Python 3.3 and higher. fastjsonschema implements validation of JSON documents by JSON schema. The library implements JSON schema drafts 04, 06, and 07. The main purpose is to have a really fast implementation. See some numbers: Probably the most popular, jsonschema, can take ...