POST/text

Compare Text

Compute a diff between two text strings with configurable output formats.

Parameters

Diffchecker-Versionheaderstring

API version to serve the request with. Defaults to the newest version, currently 1, when omitted. An unsupported version is rejected with 400 UNSUPPORTED_API_VERSION. See Versioning and Deprecation in the getting started guide.

Values: 1

Default: 1

emailquerystring

Your email address. Required if not using an API key.

output_typequerystringrequired

Specifies the type of output you receive in the response body. - json: Row metadata generated from diff computation (Content-Type: application/json) - html: Same HTML/CSS you see on the Diffchecker site (Content-Type: text/html) - html_json: Same HTML/CSS you see on the Diffchecker site, but split up and embedded in JSON (Content-Type: application/json) - markdown: A readable list of every change, with change counts and line numbers (Content-Type: text/markdown) - patch: A unified patch that turns left into right, for git apply or patch (Content-Type: text/x-diff)

Values: json, html, html_json, markdown, patch

diff_levelquerystring

Specifies how finely changed text is compared. smart chooses between word and character changes, and line reports whole changed lines. Default is word.

Values: smart, word, character, line

Default: word

ignore_casequerystring

Whether to ignore changes that only affect letter case. Default is false.

Values: true, false

Default: false

ignore_whitespacequerystring

Whether to ignore whitespace changes other than line breaks. Supports up to 200,000 whitespace characters per comparison. Default is false.

Values: true, false

Default: false

show_movesquerystring

Whether to report relocated text as moves. When false, it is reported as a deletion and an insertion. Default is true.

Values: true, false

Default: true

patch_pathquerystring

The relative file path to name in a patch, so it applies to the right file. Used only with output_type=patch. Default is file.txt. ignore_case, ignore_whitespace, show_moves and diff_level do not affect a patch, which always reproduces right exactly.

Request Bodyrequired

leftstringrequired

Left text you want to diff.

rightstringrequired

Right text you want to diff.

Responses

Every response includes the X-Credits-Used header. In JSON responses, the same value is also available in the creditsUsed field.

Diff computed successfully.

application/json

One of:

creditsUsedintegerrequired

Credits charged for the diff request.

rowsobject[]required
endboolean
startboolean
insideChangedboolean
leftobject
chunksobject[]
valuestring
typestring

Enum: equal, insert, remove

lineinteger
rightobject
chunksobject[]
valuestring
typestring

Enum: equal, insert, remove

lineinteger
addedintegerrequired

Number of added chunks.

removedintegerrequired

Number of removed chunks.

creditsUsedintegerrequired

Credits charged for the diff request.

htmlstringrequired

HTML markup of the diff table.

cssstringrequired

CSS styles for the diff table.

Example: output_type=json
{
  "creditsUsed": 1,
  "rows": [
    {
      "end": false,
      "left": {
        "chunks": [
          {
            "value": "roses are ",
            "type": "equal"
          },
          {
            "value": "red",
            "type": "remove"
          }
        ],
        "line": 1
      },
      "right": {
        "chunks": [
          {
            "value": "roses are ",
            "type": "equal"
          },
          {
            "value": "green",
            "type": "insert"
          }
        ],
        "line": 1
      },
      "insideChanged": true,
      "start": true
    },
    {
      "end": true,
      "left": {
        "chunks": [
          {
            "value": "",
            "type": "remove"
          },
          {
            "value": "violets are ",
            "type": "equal"
          },
          {
            "value": "blue",
            "type": "remove"
          }
        ],
        "line": 2
      },
      "right": {
        "chunks": [
          {
            "value": "",
            "type": "insert"
          },
          {
            "value": "violets are ",
            "type": "equal"
          },
          {
            "value": "purple",
            "type": "insert"
          }
        ],
        "line": 2
      },
      "insideChanged": true
    }
  ],
  "added": 3,
  "removed": 3
}
Example: output_type=html_json
{
  "creditsUsed": 1,
  "html": "<table class=\"diff-table\">...</table>",
  "css": ".diff-table { font-family: monospace; ... }"
}

text/html

string

text/markdown

string

text/x-diff

string

Example Request

curl
curl -X POST \
  "https://api.diffchecker.com/public/text?email=your@email.com&output_type=json&diff_level=word&ignore_case=false&ignore_whitespace=false&show_moves=true&patch_path=%7Bpatch_path%7D" \
  -H "Content-Type: application/json" \
  -d '{
  "left": "roses are red\nviolets are blue",
  "right": "roses are green\nviolets are purple"
}'

Try It