json-diff icon indicating copy to clipboard operation
json-diff copied to clipboard

Exit code is 0 even if there is a mismatch.

Open vi opened this issue 4 years ago • 3 comments

$ json_diff d '{} ' ' {}' ; echo $?

No mismatch was found.
0
$ json_diff d '[] ' ' {}' ; echo $?
Mismatch at root.
0

vi avatar Aug 20 '21 21:08 vi

Mismatch in the input json does not necessarily mean a failure for the tool itself.

Frankly, I am not convinced that the tool needs to return a non-zero exit code if the inputs don't match. Can you help me with your use case?

ksceriath avatar Aug 21 '21 07:08 ksceriath

Typically comparison tools (e.g. diff, cmp) return non-zero exit code to mean "mismatch" and zero code to mean "no differences".

Failure for the tool itself is typically signaled by the non-zero non-one exit code, e.g. "2".

Exit code distinction is typically needed for comparting JSONs noninteractively. json_diff's comparison ignores whitespace and order of keys, which is tricky to attain in Bash without using additional tools.

vi avatar Aug 21 '21 10:08 vi

Okay, yeah that makes sense.

ksceriath avatar Aug 21 '21 11:08 ksceriath