/textCompare Text
Compute a diff between two text strings with configurable output formats.
Parameters
Diffchecker-VersionheaderstringAPI 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
emailquerystringYour email address. Required if not using an API key.
output_typequerystringrequiredSpecifies 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_levelquerystringSpecifies 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_casequerystringWhether to ignore changes that only affect letter case. Default is false.
Values: true, false
Default: false
ignore_whitespacequerystringWhether 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_movesquerystringWhether 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_pathquerystringThe 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
leftstringrequiredLeft text you want to diff.
rightstringrequiredRight 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:
creditsUsedintegerrequiredCredits charged for the diff request.
rowsobject[]requiredendbooleanstartbooleaninsideChangedbooleanleftobjectchunksobject[]valuestringtypestringEnum: equal, insert, remove
lineintegerrightobjectchunksobject[]valuestringtypestringEnum: equal, insert, remove
lineintegeraddedintegerrequiredNumber of added chunks.
removedintegerrequiredNumber of removed chunks.
creditsUsedintegerrequiredCredits charged for the diff request.
htmlstringrequiredHTML markup of the diff table.
cssstringrequiredCSS 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
stringtext/markdown
stringtext/x-diff
stringExample Request
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"
}'