A PATCH framework for Python.
RFC 6902 (JSON Patch) is intentionally minimal and transport-focused. That is great for interoperability, but modern PATCH traffic crosses trust boundaries: browser clients, internal services, third-party integrations, and increasingly LLM-generated patch payloads.
-
Input Safety: patch operations are Pydantic models, so malformed payloads fail fast with clear, structured errors.
-
FastAPI Native: set up PATCH routes quickly with minimal boilerplate.
-
Richer Operations: define custom patch operations such as
increment,toggle, orreplace_substringso updates express intent directly instead of relying on brittle sequences of low-level steps. -
Typed Targeting: pointers participate in typed contracts, with clear failure modes when a resolved path has the wrong shape or type.
-
Expressive Targeting: use standard JSON Pointer, the new RFC 9535 JSONPath, or your own custom resolver.
-
OpenAPI in Sync: OpenAPI is generated from the same runtime patch models, so documentation stays aligned automatically.
-
Surface Control: operations can be allow-listed per route to limit what clients can do.
-
Lifecycle Management: evolve operation contracts over time with additive schema changes and deprecations.
pip install jsonpatchxfrom jsonpatchx import JsonPatch
doc = {"name": "Ada", "roles": ["engineer"]}
patch = JsonPatch.from_string(
"""
[
{"op": "replace", "path": "/name", "value": "Ada Lovelace"},
{"op": "add", "path": "/roles/-", "value": "maintainer"}
]
"""
)
updated = patch.apply(doc)from fastapi import FastAPI
from pydantic import BaseModel, EmailStr
from jsonpatchx import JsonPatchFor
class User(BaseModel):
id: int
email: EmailStr
active: bool
app = FastAPI()
@app.patch("/users/{user_id}", response_model=User)
def patch_user(user_id: int, patch: JsonPatchFor[User]) -> User:
user = load_user(user_id)
updated = patch.apply(user)
save_user(user_id, updated)
return updatedNote: For registries, custom operations, JSONSelector/JSONPath targeting, and optional FastAPI route helpers, see the User Guide.
See the open issues for a list of proposed features (and known issues).
JsonPatchX is a safe experimentation surface for the future of JSON Patch. With the standardization of JSONPath, the ecosystem is in a good place to explore more expressive mutation contracts.
- Discuss: join the project Discussions or the broader json-patch2 forum.
- Contribute: see CONTRIBUTING.md to help shape the roadmap. Contributions are greatly appreciated.
Distributed under the MIT License. See LICENSE for more information.
Angela Liss - chamsester@gmail.com
Project Link: https://github.com/angela-tarantula/jsonpatchx
Thanks to these foundational projects:
And to these excellent alternatives: