Consume JSON diff output in automation

Capture a committed comparison as JSON:

mergeway-diff --format json HEAD~1 HEAD > semantic-diff.json

Check the schema version before consuming entries. With jq:

jq -e '.version == 1' semantic-diff.json >/dev/null
jq -r '.entries[] | [.kind, .type, .object_id] | @tsv' semantic-diff.json

Diff exits 0 for both empty and non-empty comparisons. Test the array when a workflow needs to branch:

if jq -e '.entries | length > 0' semantic-diff.json >/dev/null; then
  echo "Semantic changes found"
else
  echo "No semantic changes"
fi

Keep command failure separate from a non-empty result:

if ! mergeway-diff --format json HEAD~1 HEAD > semantic-diff.json; then
  echo "Diff could not load or compare the repository" >&2
  exit 1
fi

On failure, the command writes a categorized diagnostic to standard error and does not emit a partial JSON document. Consumers should reject a top-level version they do not support, tolerate additional fields, and switch on kind before reading kind-specific fields. The JSON schema reference defines value, changes, and source arrays.