Skip to content

Diff

Standard · 1 credit

Compare two texts and get the differences as a unified diff or a structured list of changes.

FieldTypeRequiredDefaultDescription
originalstringYesOriginal text
modifiedstringYesModified text
formatstringNounifiedOutput format: unified, changes
context_linesintegerNo3Lines of surrounding context in unified format (0–20)
FieldTypeDescription
diffstringUnified diff string (when format is unified)
stats.additionsintegerNumber of added lines
stats.deletionsintegerNumber of deleted lines
hunksarrayDetailed hunk info — each has original_start, original_count, modified_start, modified_count, changes
changesarrayFlat list when format is changes — each has type (insert, delete, equal) and text

hunks appears in unified format responses. Top-level changes appears in changes format responses.

Terminal window
curl -X POST https://morso.dev/api/diff \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"original": "hello world\nfoo bar", "modified": "hello morso\nfoo bar\nnew line"}'
{
"diff": "--- original\n+++ modified\n@@ -1,2 +1,3 @@\n-hello world\n+hello morso\n foo bar\n+new line",
"stats": {
"additions": 2,
"deletions": 1
},
"hunks": [
{
"original_start": 1,
"original_count": 2,
"modified_start": 1,
"modified_count": 3,
"changes": [
{ "type": "delete", "text": "hello world" },
{ "type": "insert", "text": "hello morso" },
{ "type": "equal", "text": "foo bar" },
{ "type": "insert", "text": "new line" }
]
}
]
}
Terminal window
curl -X POST https://morso.dev/api/diff \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"original": "hello world", "modified": "hello morso", "format": "changes"}'
{
"stats": {
"additions": 1,
"deletions": 1
},
"changes": [
{ "type": "delete", "text": "hello world" },
{ "type": "insert", "text": "hello morso" }
]
}