Skip to content
Diff for JSON in Elixir
Branch: master
Clone or download
Latest commit 5d565fe Nov 22, 2018
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
config
js
lib Use mix format Nov 22, 2018
profile
test Use mix format Nov 22, 2018
.formatter.exs Mix format everything Mar 31, 2018
.gitignore Add better test coverage and performance profiling Nov 9, 2015
LICENSE.md Add licence Oct 26, 2015
README.md Real documentation Nov 9, 2015
mix.exs
mix.lock
package.json
stress_check.sh Better random tests with bash scripts Apr 3, 2018
stress_js_check.sh

README.md

JsonDiffEx

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

You can’t perform that action at this time.