Home

Awesome

JsonDiffEx

Build Status

Diff and patch for JSON in Elixir, works really well and is really fast

Installation

First, add JsonDiffEx to your mix.exs dependencies:

def deps do
  [{:json_diff_ex, "~> 0.5.0"}]
end

Then, update your dependencies:

$ mix deps.get

Using

Diff

Simple example:

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

Now with list:

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

Now with a map in the map:

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

Now with a map in an list in the map:

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

Patch

Simple example of a patch:

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

Now a patch with list:

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:

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

Now with a map in an list in the map:

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

Compatibility

Should work with jsondiffpatch and the test cases currently test make sure we keep that compatibility.

Profiling

Get medium profiling tests

$ MIX_ENV=test mix run profile/get_usda_json.exs

Run medium profiling tests

$ MIX_ENV=test mix run profile/medium.exs

Run medium profiling tools

$ MIX_ENV=test mix profile.fprof profile/medium.exs

Get big profiling tests

$ MIX_ENV=test mix run profile/get_mtg_json.exs

Run big profiling tests

$ MIX_ENV=test mix run profile/big.exs

Do not run the big profile with mix profile.fprof unless you have a really good computer and don't mind crashing your computer, haven't been able to finish it my self.

Links

Package

Documentation