View Source Jsonpatch.Operation.Add (Jsonpatch v2.2.0)

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

@type t() :: %Jsonpatch.Operation.Add{path: String.t(), value: any()}

Functions