JsonDiffEx (json_diff_ex v0.7.0)
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"}}
If you have problems with using both integers and floats you can override the strict comparison:
iex> JsonDiffEx.diff(%{a: 2100}, %{a: 2.1e3}, strict_equality: false)
%{}
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.