Jsonpatch v0.6.1 Jsonpatch.Mapper View Source
Maps JSON patches between regular maps and Jsonpatch.Operations.
Link to this section Summary
Functions
Creates JSON patch struct/s from a single or list maps which represents JSON patches.
Link to this section Functions
Specs
from_map(map() | [map()]) :: [Jsonpatch.Operation.t()] | Jsonpatch.Operation.t() | {:error, :invalid}
Creates JSON patch struct/s from a single or list maps which represents JSON patches.
Examples
iex> add_patch_map = %{"op" => "add", "path" => "/name", "value" => "Alice"}
iex> Jsonpatch.Mapper.from_map(add_patch_map)
%Jsonpatch.Operation.Add{path: "/name", value: "Alice"}
iex> unkown_patch_map = %{"op" => "foo", "path" => "/name", "value" => "Alice"}
iex> Jsonpatch.Mapper.from_map(unkown_patch_map)
{:error, :invalid}
Specs
to_map(Jsonpatch.Operation.t() | [Jsonpatch.Operation.t()]) :: map() | {:error, :invalid}