Jsonpatch v0.6.1 Jsonpatch.Coder View Source
Cares of de- and encoding of json patches.
Link to this section Summary
Link to this section Functions
Specs
decode(iodata()) :: {:error, :invalid} | Jsonpatch.Operation.t() | [Jsonpatch.Operation.t()]
Decodes a JSON patch string into patch structs.
Examples
iex> Jsonpatch.Coder.decode("{\"op\": \"add\",\"value\": \"1\",\"path\": \"/age\"}")
{:ok, %Jsonpatch.Operation.Add{path: "/age", value: 1}}
Specs
encode([Jsonpatch.Operation.t()] | Jsonpatch.Operation.t()) :: {:ok, iodata()} | {:ok, String.t()} | {:error, {:invalid, any()}} | {:error, :invalid}
Encodes a patch into a JSON string.
Examples
iex> Jsonpatch.Coder.encode(%Jsonpatch.Operation.Add{path: "/age", value: 1})
{:ok, "{\"op\": \"add\",\"value\": \"1\",\"path\": \"/age\"}"}