JSON Patch for modern PATCH APIs. Tested against the RFC 6902 Compliance Test Suite.
Built on Pydantic models, with typed JSON Pointer / JSONPath targeting, custom patch operations, and first-class support for FastAPI PATCH routes and OpenAPI generation.
pip install jsonpatchxFor FastAPI integrations:
pip install jsonpatchx[fastapi]- Documentation: https://angela-tarantula.github.io/jsonpatchx/user-guide/getting-started
- Chengelog: https://github.com/angela-tarantula/jsonpatchx/blob/main/CHANGELOG.md
- PyPI: https://pypi.org/project/jsonpatchx
- Source code: https://github.com/angela-tarantula/jsonpatchx
- Issue tracker: https://github.com/angela-tarantula/jsonpatchx/issues
- Project Discussions: https://github.com/angela-tarantula/jsonpatchx/discussions
- IETF Future Standards Discussions: https://github.com/json-patch/json-patch2
from 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 custom operations, JSONPath targeting, route-level controls, and more, see the User Guide.
See CONTRIBUTING.md for local setup, checks, docs preview, and pull request expectations.
Use Discussions for project-specific design conversation, issues for concrete bugs or proposed work, and the broader json-patch2 forum for standards discussion.
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: