andreyvit / json-diff

Structural diff for JSON files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Collapse repeated elision into one line

FireyFly opened this issue · comments

Currently, when diffing arrays, elements that are objects and equivalent on both sides get elided with a .... However, the fact that the elision marker is there is important to highlight the position of the differences in the array.

In some cases (especially when diffing API responses and similar), the arrays might be very long, and the output gets rather tedious. Instead of one elision marker for each elided object, I suggest to replace repetated elision with a single line.

E.g.,

% json-diff <(echo '{ "hello": [{},{},{},{},{},{},1] }') <(echo '{ "hello": [{},{},{},{},{},{},2] }')
 {
   hello: [
     ...
     ...
     ...
     ...
     ...
     ...
-    1
+    2
   ]
 }

would instead become

% json-diff <(echo '{ "hello": [{},{},{},{},{},{},1] }') <(echo '{ "hello": [{},{},{},{},{},{},2] }')
 {
   hello: [
     ... (6 entries)
-    1
+    2
   ]
 }

For smaller arrays, it would get noisy and reduce clarity to use the elisions everywhere. Therefore, I think it makes sense to by default only collapse e.g. 5 or more elisions into one line. Probably makes sense to provide a command-line flag to set this threshold, though!

Just to link the issue and PR together... soon after opening this issue, I opened a PR which resolves it: #42 Collapse elisions.