Free plan

Compare text

Compare two texts and see what was added or removed
POST
/v1/documents/text-diff

About this tool

This tool compares two pieces of text and shows the differences. Paste the two texts, or add two text files. You can compare by line, word, letter or sentence, and ignore capital letters or spaces. You get the changes, a similarity score, and optionally a page that shows changes in colour.
For example, you compare two versions of an article to see what the editor changed.

How to use it

  1. Choose this tool.
  2. Paste the older text and the newer text, or add two text files.
  3. Choose how to compare: by line, word, letter or sentence.
  4. Press Generate.
  5. Read the changes on screen or open the coloured page.

What you get back

You get the list of changes with a similarity score on screen. If you asked, you also get a coloured page to download.
GOOD TO KNOW
Both texts are needed, as parameters or as files. Counts as one document.
TEST IT LIVE

Try Compare text in the Studio

One click opens the Studio with this tool already selected. Add your file and see the result in seconds.
Open in the Studio
Family
Documents
Plan
Free
Method
POST
Endpoint
/v1/documents/text-diff
Tool ID
documents.text-diff
Authentication
API key
Accepts
Text and settings
Background jobs
Yes
Usage group
Documents
For developers

Use it from your code

cURL

curl -X POST "https://app.h2i.davixlabs.io/v1/documents/text-diff" \
  -H "X-Api-Key: $DAVIX_H2I_API_KEY" \
  -F 'a=one
two
three' \
  -F 'b=one
2
three' \
  -F 'mode=line'

Node.js

const { DavixH2I } = require('@davixlabs/h2i-sdk');

const h2i = new DavixH2I({ apiKey: process.env.DAVIX_H2I_API_KEY, baseUrl: process.env.DAVIX_H2I_URL });
const result = await h2i.documents.textDiff({
    "a": "one\ntwo\nthree",
    "b": "one\n2\nthree",
    "mode": "line"
  });
console.log(result.data, result.requestId);

PHP

<?php
require 'vendor/autoload.php';

$h2i = new \Davix\H2I\Client(['apiKey' => getenv('DAVIX_H2I_API_KEY'), 'baseUrl' => getenv('DAVIX_H2I_URL')]);
$result = $h2i->documents()->textDiff([
    'a' => 'one
two
three',
    'b' => 'one
2
three',
    'mode' => 'line',
]);
echo $result->requestId;
FAQ

Frequently asked questions

Compare two texts (as parameters, or as two text files) by line, word, character or sentence: a unified patch, the list of changes with line numbers, a similarity score and an optional page that shows the changes in colour.

Compare text works from text and settings, so no file is needed. Every input is optional.

Compare text is included in every plan, including Free. Each run uses credits from your monthly allowance.

Send a POST request to /v1/documents/text-diff with your API key in the X-Api-Key header. Official SDKs for Node.js, Python, PHP, Go, Java, .NET and Ruby do the same for you, and the code box on this page shows ready-to-copy examples. For large work it can also run as a background job, so your request returns straight away.