Guide
Comparing text and code with a diff checker
By Logappradeep · ServiceNow developer
A diff shows exactly what changed between two versions of a text. Instead of reading both versions and hoping to spot the difference, you see removed lines, added lines and changed characters highlighted. Diffs are at the heart of version control and code review, but they are just as handy for comparing configuration files, API responses, contracts, translations or two exports of the same report.
How diff algorithms work
Finding the differences between two texts is a classic computer science problem. Most diff tools look for the longest common subsequence, the largest set of lines that appear in both versions in the same order. Everything outside that common backbone is reported as a deletion from the left side or an insertion on the right. Algorithms in the family of Eugene Myers' 1986 O(ND) algorithm, the approach behind Git's default diff, solve this efficiently and prefer the smallest set of edits. Once lines are paired up, a second pass highlights the individual characters that changed within each modified line.
What this diff checker offers
The tool is built on the Monaco diff editor, the editor component used in Visual Studio Code. Paste or type into the Original (left) and Modified (right) panes, both of which are editable, or load a file into either side. Choose a language such as JSON, JavaScript, TypeScript, Python, SQL, YAML or Markdown for syntax highlighting. Switch between Split view, which shows the versions side by side, and Inline view, which interleaves them in one column. Arrow buttons next to each change copy that block from one side to the other, which lets you merge selectively. A summary shows additions, deletions, unchanged lines and an approximate similarity percentage, and you can swap sides, go full screen or download a simple patch file.
Practical uses
- Spotting what changed between two versions of a config file or
.envtemplate. - Comparing API responses from staging and production.
- Reviewing edits to a contract, policy or documentation page.
- Checking a generated file against the expected output in a test.
Pitfalls
Whitespace and line endings. Files from Windows use \r\n line endings and files from macOS or Linux use \n; trailing spaces and tabs versus spaces also count as changes. Turn on Ignore Spaces to skip leading and trailing whitespace differences when they are not meaningful.
Reformatted data. If one JSON file is minified and the other pretty-printed, or keys are in a different order, nearly every line differs even though the data is the same. Format both sides consistently first, or use a structural JSON diff.
Similarity is approximate. The percentage compares sets of lines, so moved or duplicated lines can make it look higher or lower than the visual diff suggests.
Comparison runs in your browser; nothing is uploaded. Both texts and your view settings are saved in local storage, so clear the workspace when you compare sensitive material on a shared computer.