Text Comparison
The /diff endpoint compares two texts and returns an ordered list of changes, line by line or word by word.
How it works?
The comparison relies on the Longest Common Subsequence (LCS) algorithm: it finds the largest set of segments shared by both texts in the same order, and everything outside that set is reported as added or removed. In line mode the texts are split on newlines, keeping empty lines; in word mode they are split on whitespace runs and empty segments are dropped.
curl -X POST \ "https://api.moxon.dev/v6/diff" \ -H "Content-Type: application/json" \ -d '{}'Send the request to see the response here.
The request body must be JSON:
astringrequiredOriginal text
bstringrequiredModified text, compared against
amode"line" | "word"optionalComparison granularity:
lineorword. Default:line
| Mode | Description |
|---|---|
line | Splits both texts on newlines and compares line by line |
word | Splits both texts on whitespace and compares word by word |
modestringGranularity used:
lineorwordaddednumberNumber of segments present only in
bremovednumberNumber of segments present only in
achangesobject[]Ordered changes rebuilding
bfroma
changes entries:
typestringequal,addordelvaluestringThe line or word this change applies to
If parameters are missing or invalid, the API will return an error:
- 400
Please provide a first text (a={text})Theaparameter is missing or is not a string - 400
Please provide a second text (b={text})Thebparameter is missing or is not a string - 400
Texts must be 10000 characters or feweraorbexceeds the maximum length - 400
Mode must be one of: line, wordThemodevalue is notlineorword - 400
Texts must contain 2000 lines or fewerA text has more lines than the limit inlinemode - 400
Texts must contain 2000 words or fewerA text has more words than the limit inwordmode
Last updated on September 12, 2026