Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/jiaoyinyi/maps_diff
erlang compare json like maps data differences
https://github.com/jiaoyinyi/maps_diff
bson compare-data erlang json
Last synced: 16 days ago
JSON representation
erlang compare json like maps data differences
- Host: GitHub
- URL: https://github.com/jiaoyinyi/maps_diff
- Owner: jiaoyinyi
- License: apache-2.0
- Created: 2024-09-04T10:38:50.000Z (2 months ago)
- Default Branch: master
- Last Pushed: 2024-09-21T08:52:27.000Z (about 2 months ago)
- Last Synced: 2024-10-16T15:09:46.460Z (about 1 month ago)
- Topics: bson, compare-data, erlang, json
- Language: Erlang
- Homepage:
- Size: 13.7 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
maps_diff
=====对比json形式的maps数据差异
Comparison of json like maps data differences### 对比差异(compare diff)
```
Map1 = #{
<<"a">> => 10
, <<"b">> => [5, 10]
, <<"del">> => 10
},
Map2 = #{
<<"a">> => 10
, <<"b">> => [10, 20]
, <<"c">> => #{<<"msg">> => <<"hello">>, <<"data">> => 10}
, <<"new">> => 10
},#{<<"b">> =>
#{0 => {maps_diff,update,5,10},
1 => {maps_diff,update,10,20}},
<<"c">> =>
{maps_diff,add,undefined,#{<<"data">> => 10,<<"msg">> => <<"hello">>}},
<<"del">> => {maps_diff,delete,10,undefined},
<<"new">> => {maps_diff,add,undefined,10}
} = maps_diff:diff(Map1, Map2).
```### 整合差异(merge diff)
```
Map1 = #{
<<"a">> => 10
, <<"b">> => [5, 10]
, <<"del">> => 10
},
Map2 = #{
<<"a">> => 10
, <<"b">> => [10, 20]
, <<"c">> => #{<<"msg">> => <<"hello">>, <<"data">> => 10}
, <<"new">> => 10
},
Map3 = #{
<<"a">> => 10
, <<"b">> => [10, 20]
, <<"c">> => #{<<"msg">> => <<"hello">>}
},
Diff1 = #{
<<"b">> =>
#{0 => {maps_diff,update,5,10},
1 => {maps_diff,update,10,20}},
<<"c">> =>
{maps_diff,add,undefined,#{<<"data">> => 10,<<"msg">> => <<"hello">>}},
<<"del">> => {maps_diff,delete,10,undefined},
<<"new">> => {maps_diff,add,undefined,10}
} = maps_diff:diff(Map1, Map2),Diff2 = #{
<<"c">> => #{<<"data">> => {maps_diff,delete,10,undefined}},
<<"new">> => {maps_diff,delete,10,undefined}
} = maps_diff:diff(Map2, Map3),#{
<<"b">> =>
#{0 => {maps_diff,update,5,10},
1 => {maps_diff,update,10,20}},
<<"c">> =>
{maps_diff,add,undefined,#{<<"msg">> => <<"hello">>}},
<<"del">> => {maps_diff,delete,10,undefined}
} = maps_diff:merge(Diff1, Diff2).
```### TODO
* 待支持限定层级对比