View Source Jsonpatch.Operation.Add (Jsonpatch v2.2.1)
The add operation is the operation for creating/updating values.
Values can be inserted in a list using an index or appended using a -
.
Examples
iex> add = %Add{path: "/a/b", value: 1}
iex> target = %{"a" => %{"c" => false}}
iex> Jsonpatch.Operation.Add.apply(add, target, [])
{:ok, %{"a" => %{"b" => 1, "c" => false}}}
iex> add = %Add{path: "/a/1", value: "b"}
iex> target = %{"a" => ["a", "c"]}
iex> Jsonpatch.Operation.Add.apply(add, target, [])
{:ok, %{"a" => ["a", "b", "c"]}}
iex> add = %Add{path: "/a/-", value: "z"}
iex> target = %{"a" => ["x", "y"]}
iex> Jsonpatch.Operation.Add.apply(add, target, [])
{:ok, %{"a" => ["x", "y", "z"]}}
Summary
Types
Functions
@spec apply( Jsonpatch.t(), target :: Jsonpatch.Types.json_container(), Jsonpatch.Types.opts() ) :: {:ok, Jsonpatch.Types.json_container()} | Jsonpatch.Types.error()