Jsonpatch v0.6.1 Jsonpatch.Operation behaviour View Source
Defines behaviour for apply a patch to a struct.
Link to this section Summary
Functions
Uses a JSON patch path to get the last map that this path references.
Determines the sort value for the operation of a patch. This value assure in which order patches are applied. (Example: shall remove patches be applied before add patches?)
Updatest a map reference by a given JSON patch path with the new final destination.
Link to this section Types
Specs
t() :: Jsonpatch.Operation.Add.t() | Jsonpatch.Operation.Remove.t() | Jsonpatch.Operation.Replace.t() | Jsonpatch.Operation.Copy.t() | Jsonpatch.Operation.Move.t() | Jsonpatch.Operation.Test.t()
A valid Jsonpatch operation by RFC 6902
Link to this section Functions
Specs
get_final_destination(map(), binary()) :: {map(), binary()} | {list(), binary()} | {:error, :invalid_path}
Uses a JSON patch path to get the last map that this path references.
Examples
iex> path = "/a/b/c/d"
iex> target = %{"a" => %{"b" => %{"c" => %{"d" => 1}}}}
iex> Jsonpatch.Operation.get_final_destination(target, path)
{%{"d" => 1}, "d"}
iex> # Invalid path
iex> path = "/a/e/c/d"
iex> target = %{"a" => %{"b" => %{"c" => %{"d" => 1}}}}
iex> Jsonpatch.Operation.get_final_destination(target, path)
{:error, :invalid_path}
iex> path = "/a/b/1/d"
iex> target = %{"a" => %{"b" => [true, %{"d" => 1}]}}
iex> Jsonpatch.Operation.get_final_destination(target, path)
{%{"d" => 1}, "d"}
iex> # Invalid path
iex> path = "/a/b/42/d"
iex> target = %{"a" => %{"b" => [true, %{"d" => 1}]}}
iex> Jsonpatch.Operation.get_final_destination(target, path)
{:error, :invalid_path}
Specs
Determines the sort value for the operation of a patch. This value assure in which order patches are applied. (Example: shall remove patches be applied before add patches?)
Specs
Updatest a map reference by a given JSON patch path with the new final destination.
Examples
iex> path = "/a/b/c/d"
iex> target = %{"a" => %{"b" => %{"c" => %{"d" => 1}}}}
iex> Jsonpatch.Operation.update_final_destination(target, %{"e" => 1}, path)
%{"a" => %{"b" => %{"c" => %{"e" => 1}}}}