Code Diff
About this tool
What is a code diff?
A code diff is a structured comparison that shows exactly what changed between two versions of a file or text block. The concept traces back to the Unix diff command, written by Douglas McIlroy in the early 1970s, which computed the minimal set of line-level edits needed to transform one file into another. Modern version control systems like Git build on this foundation — the git diff command is one of the most frequently used operations in any developer workflow. Diffs are central to code review, where reviewers inspect pull request changes line by line to catch bugs, enforce style guidelines, and discuss architecture decisions. They also appear in CI/CD pipelines, where deployment scripts compare configuration files before applying changes to production, and in database migration tools that diff schema definitions to generate ALTER statements automatically.
Understanding diff output
In the side-by-side view used by this tool, additions are highlighted in green on the right panel and deletions are highlighted in red on the left panel. Lines present in both versions appear without highlighting and serve as context anchors so you can locate changes within the surrounding code. This side-by-side format — as opposed to the unified diff format you see in terminal output or GitHub pull requests — makes it easier to track structural changes because the original and modified versions are visually aligned. Under the hood, this tool uses CodeMirror's merge view extension, which computes the diff at the character level, so even small inline edits within a line are marked precisely rather than flagging the entire line as changed.
Normalize JSON for cleaner diffs
When comparing JSON documents, key order differences can create noisy diffs that obscure the actual data changes. The "Normalize JSON" button in the toolbar sorts all object keys alphabetically and recursively through nested structures before running the comparison. This means two JSON objects with identical data but different key ordering will produce a clean, empty diff instead of a wall of false positives. This feature is particularly useful when comparing API responses captured at different times, exported configuration files from different environments, or serialized state objects where property insertion order is not guaranteed.
Related tools
Use the JSON Formatter to pretty-print and validate JSON before diffing, or the JWT Debugger to decode and compare JWT token payloads.
Frequently Asked Questions
How do I compare two code snippets?
Paste, type, or drag-and-drop your code into the left (original) and right (modified) panels. Differences are highlighted automatically: additions appear in green and deletions in red, giving you instant visual feedback on what changed between the two versions. The tool uses CodeMirror's merge view to render a side-by-side diff with inline change markers. Language detection runs automatically as you type, analyzing syntax patterns such as curly braces, keywords, and indentation style to select the correct highlighter. If the auto-detection picks the wrong language, you can override it manually using the language dropdown in the toolbar. This makes the tool suitable for comparing everything from JSON API responses and TypeScript modules to Python scripts and SQL queries, all without any server-side processing.
What is a code diff?
A diff (short for "difference") is a structured representation of the changes between two versions of text or code. The concept originates from the Unix diff command, first released in the early 1970s, which compared files line by line and output a minimal set of changes needed to transform one file into the other. Today, diffs are fundamental to version control systems like Git, where commands such as git diff show staged or unstaged modifications. In code review workflows, diffs allow reviewers to focus on exactly what changed in a pull request rather than reading entire files. Diffs are also used in deployment pipelines to verify configuration changes before they reach production. This tool renders a side-by-side diff view, making additions, deletions, and unchanged context lines immediately visible.
Which programming languages are supported?
This tool supports syntax highlighting for JSON, JavaScript, TypeScript, Go, YAML, Python, SQL, and plain text. Syntax highlighting colors language keywords, strings, numbers, and structural tokens so that diffs are easier to read and logical changes stand out from mere formatting shifts. The auto-detection algorithm examines the content you paste and looks for distinctive patterns: JSON is identified by leading braces and quoted keys, Go by keywords like func and package, Python by def and indentation-based blocks, YAML by key-colon-value structures, and SQL by SELECT, FROM, and JOIN clauses. JavaScript and TypeScript are distinguished by the presence of type annotations. If the detector guesses incorrectly, select the correct language from the toolbar dropdown to apply the right grammar immediately.