Jsonpatch.Operation.Add (Jsonpatch v0.12.0) View Source

The add operation is the operation for adding values to a map or struct. Values can be appended to lists by using - instead of an index.

Examples

iex> add = %Jsonpatch.Operation.Add{path: "/a/b", value: 1}
iex> target = %{"a" => %{"c" => false}}
iex> Jsonpatch.Operation.apply_op(add, target)
%{"a" => %{"b" => 1, "c" => false}}

iex> add = %Jsonpatch.Operation.Add{path: "/a/-", value: "z"}
iex> target = %{"a" => ["x", "y"]}
iex> Jsonpatch.Operation.apply_op(add, target)
%{"a" => ["x", "y", "z"]}

Link to this section Summary

Link to this section Types

Specs

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