jschon.jsonpatch
- class jschon.jsonpatch.JSONPatch(*operations)
RFC 6902-conformant JSON Patch implementation.
- __delitem__(index)
Delete self[index].
- Parameters:
index (int) –
- Return type:
None
- __eq__(other)
Return self == other.
- Parameters:
other (JSONPatch | Iterable[JSONPatchOperation | Mapping[str, None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]]]) –
- Return type:
bool
- __getitem__(index: int) JSONPatchOperation
- __getitem__(index: slice) JSONPatch
Return self[index].
- __init__(*operations)
Initialize a
JSONPatch
instance from the given operations, each of which may be aJSONPatchOperation
or a JSON patch operation-conformant dictionary.- Parameters:
operations (JSONPatchOperation | Mapping[str, None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]]) –
- Return type:
None
- __len__()
Return len(self).
- Return type:
int
- __repr__()
Return repr(self).
- Return type:
str
- __setitem__(index, operation)
Set self[index] to operation.
- Parameters:
index (int) –
operation (JSONPatchOperation | Mapping[str, None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]]) –
- Return type:
None
- aslist()
Return self as a list of operation dicts.
- Return type:
List[Dict[str, None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]]]
- evaluate(document)
Return the result of sequentially applying all patch operations to document, as a new document. document itself is not modified.
- Parameters:
document (None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
- Return type:
None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]
- insert(index, operation)
Insert operation before index.
- Parameters:
index (int) –
operation (JSONPatchOperation | Mapping[str, None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]]) –
- Return type:
None
- class jschon.jsonpatch.JSONPatchOperation(*, op, path, value=None, from_=None, **kwargs)
RFC 6902-conformant JSON patch operation object.
- Parameters:
op (PatchOp) –
path (Union[str, JSONPointer]) –
value (JSONCompatible) –
from_ (Optional[Union[str, JSONPointer]]) –
kwargs (Union[str, JSONPointer]) –
- Return type:
- __eq__(other)
Return self == other.
- Parameters:
other (JSONPatchOperation | Mapping[str, None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]]) –
- Return type:
bool
- static __new__(cls, *, op, path, value=None, from_=None, **kwargs)
Create and return a new
JSONPatchOperation
instance.- Parameters:
op (PatchOp) – The operation to perform. One of
add
,remove
,replace
,move
,copy
,test
.path (str | JSONPointer) – A JSON pointer to the target location.
value (None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) – For
add
andreplace
operations, the value to set at the target location. Fortest
, the value to compare with the target.from – The location from which to
move
orcopy
. An alias for from, which may be passed via kwargs.from_ (str | JSONPointer | None) –
kwargs (str | JSONPointer) –
- Return type:
- __repr__()
Return repr(self).
- Return type:
str
- apply(document)
Apply the patch operation to document and return the resultant document.
- Parameters:
document (None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
- Return type:
None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]
- asdict()
Return self as a dict.
- Return type:
Dict[str, None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]]
- class jschon.jsonpatch.PatchOp(value)
An enumeration.
- ADD = 'add'
- COPY = 'copy'
- MOVE = 'move'
- REMOVE = 'remove'
- REPLACE = 'replace'
- TEST = 'test'
- jschon.jsonpatch.add(document, path, value)
Add value to document at path.
- Parameters:
document (None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
path (JSONPointer) –
value (None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
- Return type:
None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]
- jschon.jsonpatch.copy(document, path, from_)
Copy the value at from_ in document to path.
- Parameters:
document (None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
path (JSONPointer) –
from_ (JSONPointer) –
- Return type:
None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]
- jschon.jsonpatch.move(document, path, from_)
Move the value at from_ in document to path.
- Parameters:
document (None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
path (JSONPointer) –
from_ (JSONPointer) –
- Return type:
None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]
- jschon.jsonpatch.remove(document, path)
Remove the value at path in document.
- Parameters:
document (None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
path (JSONPointer) –
- Return type:
None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]
- jschon.jsonpatch.replace(document, path, value)
Replace the value at path in document with value.
- Parameters:
document (None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
path (JSONPointer) –
value (None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
- Return type:
None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]
- jschon.jsonpatch.test(document, path, value)
Test whether the value at path in document is equal to value.
- Parameters:
document (None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
path (JSONPointer) –
value (None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]) –
- Return type:
None | bool | int | float | str | Sequence[Any] | Mapping[str, Any]