Skip to content

angela-tarantula/jsonpatchx

JsonPatchX

A PATCH framework for Python.

Tests Codecov OpenSSF Scorecard Contributor Covenant

About The Project

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.

JsonPatchX supports standard JSON Patch and adds a contract layer

  • 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.

It also provides extensibility beyond the RFC

  • Richer Operations: define custom patch operations such as increment, toggle, or replace_substring so 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.

And it treats the patch layer as a first-class contract

  • 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.

Getting Started

Installation

pip install jsonpatchx

Usage

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 registries, custom operations, JSONSelector/JSONPath targeting, and optional FastAPI route helpers, see the User Guide.

Roadmap

See the open issues for a list of proposed features (and known issues).

Contributing

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.

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:

About

A PATCH framework for Python.

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages