POST/text

Compare Text

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

Parameters

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)

Values: json, html, html_json

diff_levelquerystring

Specifies whether you want to diff by word or character. Default is `word`.

Values: word, character

Default: word

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

Example Request

curl
curl -X POST \
  "https://web.preview.diffchecker.com/api/public//text?email=your%40email.com&output_type=json&diff_level=word" \
  -H "Content-Type: application/json" \
  -d '{
  "left": "roses are red\nviolets are blue",
  "right": "roses are green\nviolets are purple"
}'

Try It