View Source surreal_patch (surreal v2.1.0)
Erlang-y JSON patch.
Note that this module doesn't implement JSON patch itself but provides types and converters to make surreal:patch/3
easier.
Link to this section Summary
Types
Combination of all patch types.
Adds a value to an object or inserts it into an array. In the case of an array, the value is inserted before the given index. The
-
character can be used instead of an index to insert at the end of an array.Copies a value from one location to another within the JSON document. Both
From
and Path
are JSON Pointers.Applies a diff to the document. Value field contains the actual diff to be applied.
Moves a value from one location to the other. Both
From
and Path
are JSON Pointers.Removes a value from an object or array.
Replaces a value. Equivalent to a "remove" followed by an "add".
Tests that the specified value is set in the document. If the test fails, then the patch as a whole should not apply.
Functions
Converts a given JSON Patch tuple or list into a corresponding map or list.
Link to this section Types
-type patch() :: patch_add() | patch_remove() | patch_replace() | patch_copy() | patch_move() | patch_test() | patch_diff().
-type patch_add() :: {add, Path :: iodata(), Value :: term()}.
-
character can be used instead of an index to insert at the end of an array.
-type patch_copy() :: {copy, From :: iodata(), Path :: iodata()}.
From
and Path
are JSON Pointers.
-type patch_diff() :: {diff, Path :: iodata(), Value :: iodata()}.
-type patch_move() :: {move, From :: iodata(), Path :: iodata()}.
From
and Path
are JSON Pointers.
-type patch_remove() :: {remove, Path :: iodata()}.
-type patch_replace() :: {replace, Path :: iodata(), Value :: term()}.
-type patch_test() :: {test, Path :: iodata(), Value :: term()}.