JsonDiffEx

This is the documentation of JsonDiffEx.

There are no runtime dependencies and it should be easy to use.

You can use the javascript library jsondiffpatch with it since it get’s it’s diff format from it.

It contains both diff and patch

Example

Diff

Simple example:

iex> JsonDiffEx.diff %{"test" => 1}, %{"test" => 2}
%{"test" => [1, 2]}

Now with list:

iex> JsonDiffEx.diff %{"test" => [1,2,3]}, %{"test" => [2,3]}
%{"test" => %{"_0" => [1, 0, 0], "_t" => "a"}}

Now with a map in the map:

iex> JsonDiffEx.diff %{"test" => %{"1": 1}}, %{"test" => %{"1": 2}}
%{"test" => %{"1": [1, 2]}}

Now with a map in an list in the map:

iex> JsonDiffEx.diff %{"test" => [%{"1": 1}]}, %{"test" => [%{"1": 2}]}
%{"test" => %{"0" => %{"1": [1, 2]}, "_t" => "a"}}

Patch

Simple example of a patch:

iex> JsonDiffEx.patch %{"test" => 1}, %{"test" => [1, 2]}
%{"test" => 2}

Now a patch with list:

iex> JsonDiffEx.patch %{"test" => [1,2,3]},
...> %{"test" => %{"_0" => [1, 0, 0], "_t" => "a"}}
%{"test" => [2,3]}

Now a patch with a map in the map:

iex> JsonDiffEx.patch %{"test" => %{"1": 1}}, %{"test" => %{"1": [1, 2]}}
%{"test" => %{"1": 2}}

Now with a map in an list in the map:

iex> JsonDiffEx.patch %{"test" => [%{"1": 1}]},
...> %{"test" => %{"0" => %{"1": [1, 2]}, "_t" => "a"}}
%{"test" => [%{"1": 2}]}

Summary

Functions

Diff only supports Elixir’s Map format but they can contain, lists, other maps and anything that can be compared like strings, numbers and boolean

Patch only supports Elixir’s Map format

Functions

diff(map1, map2)

Specs

diff(map, map) :: map

Diff only supports Elixir’s Map format but they can contain, lists, other maps and anything that can be compared like strings, numbers and boolean.

patch(map1, diff1)

Specs

patch(map, map) :: map

Patch only supports Elixir’s Map format.