Skip to content

angela-tarantula/jsonpatchx

JsonPatchX

PyPI Version Python Versions Tests Codecov OpenSSF Scorecard License Contributor Covenant

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.

Table of Contents

Install

pip install jsonpatchx

For FastAPI integrations:

pip install jsonpatchx[fastapi]

Links

Examples

1. Standard RFC 6902

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)

2. The FastAPI Contract

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 updated

Note: For custom operations, JSONPath targeting, route-level controls, and more, see the User Guide.

Contributing

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.

License

Distributed under the MIT License. See LICENSE for more information.

Contact

Angela Liss - chamsester@gmail.com

Project Link: https://github.com/angela-tarantula/jsonpatchx

Acknowledgements

Thanks to these foundational projects:

And to these excellent alternatives:

Packages

 
 
 

Contributors

Languages