Jsonpatch v0.7.0 Jsonpatch.Coder View Source

Cares of de- and encoding of json patches.

Link to this section Summary

Functions

Decodes a JSON patch string into patch structs.

Encodes a patch into a JSON string.

Link to this section Functions

Specs

decode(iodata()) :: {:error, :invalid} | Jsonpatch.t() | [Jsonpatch.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.t()] | Jsonpatch.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\"}"}