Diff Formatter

Compare text and code differences with formatted highlighting and side-by-side view

Runs locally

Original

Modified

Diff Result

Click Compare to see the differences between the two sides

Tips

  • Use consistent indentation in both texts for more accurate line-by-line comparison.
  • The unified view is best for small changes. Side-by-side is better for larger differences.
  • added   removed   changed
  • Use the swap button to reverse the comparison direction and see additions as removals.
  • Ctrl/Cmd + Enter compares from either input.

Two diff modes, picked automatically

Data Diff starts from whatever you paste. When both sides parse as JSON it switches to a structural diff; for everything else it compares line by line. You can also lock a mode manually with the tabs above the result.

What the JSON structural diff reports

  • Added — a key or index that exists only on the modified side, with a preview of its value.
  • Removed — a key or index that exists only on the original side.
  • Changed — the same path holds a different value on each side, shown as before → after.
  • Type changed — the path holds an object on one side and a scalar or array on the other.
  • Every entry carries a path in the same $.store.books[0].title notation used by the JSON, XML and YAML Inspectors, so you can jump straight to it in the source.

Text diff, when you need it

Line-based comparison highlights every added and removed line with line numbers. It works on code, logs, config files, and any text — including JSON whose formatting changed but whose data did not.

Example: what JSON mode sees that text mode does not

The two snippets below differ only in key order and indentation. Text diff reports almost every line as changed; JSON structural diff correctly reports zero changes.

A
{
  "name": "web",
  "version": "1.0"
}
B
{
  "version": "1.0",
  "name": "web"
}

Where this fits in your workflow

Data Diff is the compare step of the workbench. Send any document here from the other tools:

Frequently Asked Questions

Common questions about Diff Formatter formatting answered

Yes, our diff formatter is completely free with no registration required. All processing happens in your browser.

You can compare any text content: code, configuration files, JSON, XML, plain text, or any other text-based format.

Added lines are shown with a green background, removed lines with a red background, and changed lines show both versions side by side.

Yes. Click the swap button to reverse the original and modified texts, turning additions into removals and vice versa.

The tool uses the Myers diff algorithm, which is the same algorithm used by Git for text comparison, ensuring accurate and minimal diffs.

The unified diff format (-u), as produced by git diff, diff -u, and every major version control system - one or more file sections, each with ---/+++ headers, @@ hunk markers, and +/- /context lines. GNU diffutils documents the exact format; the formatter re-wraps hunks with aligned line numbers and syntax coloring.

@@ -3,7 +3,8 @@ says: in the old file, starting at line 3, 7 lines are shown; in the new file, the corresponding section starts at line 3 and spans 8 lines. Reading the counts tells you the change size at a glance - here one line was added. The formatter keeps these markers intact because patch(1) and git apply depend on them.

No - it formats and explains patches, it does not apply them. For applying, use git apply or patch -p1; for merging conflicting hunks, your VCS's merge tool. Formatting is deliberately read-only so you can safely paste any patch, including ones with rejected or conflicted hunks, for readable review.

{-- * External Resources Component(#19 Phase 3b 内容佐证工程) * 工具页「权威引用」区块:RFC / W3C / WHATWG / ECMA / IANA / 官方规范站 / 官方语言文档 / Wikipedia。 * * - 接受 :slug 属性 → 经 config/tool-sources.php 家族矩阵渲染该工具的权威引用 * - slug 未命中映射时不渲染(无权威来源的工具静默跳过) * - 链接 title 保持英文(引用源专名);description 经 * common.resources.descriptions.{key} 本地化,lang 未命中回退英文(线上不裸奔) * - 链接保持 dofollow(rel="noopener noreferrer") * * @param string|null $slug --}}

Related Tools