Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Windows Tipps & SecurityThe Blood of Dawnwalker Director Says 60 FPS Is Enough for This RPG(23.09.2026 um 14:37 Uhr)
Windows Tipps & SecurityMeyer Sound ernennt John McMahon zum Chief Operating Officer(23.09.2026 um 11:19 Uhr)
Windows Tipps & SecurityTouchscreen erweitert Grill-Sortiment am Point of Sale(23.09.2026 um 13:45 Uhr)
Windows Tipps & Security„When Worlds Unite“: ISE 2027 erweitert Messe und Programm(23.09.2026 um 13:45 Uhr)
Sichere ProgrammierungWhat Full-Stack AI Engineering Means in Real Projects(23.09.2026 um 14:00 Uhr)
Sichere ProgrammierungThe Internet Changes Everything (Slowly)(23.09.2026 um 14:09 Uhr)
Sichere ProgrammierungMAUI vs React Native vs Flutter vs Ionic(23.09.2026 um 14:09 Uhr)
Sichere ProgrammierungAI Tools Used in Modern Software Development(23.09.2026 um 14:22 Uhr)
Sichere ProgrammierungHealthAuditor — Website Health & SEO Audit Tool(23.09.2026 um 14:24 Uhr)
Windows Tipps & SecurityThe Blood of Dawnwalker Director Says 60 FPS Is Enough for This RPG(23.09.2026 um 14:37 Uhr)
Windows Tipps & SecurityMeyer Sound ernennt John McMahon zum Chief Operating Officer(23.09.2026 um 11:19 Uhr)
Windows Tipps & SecurityTouchscreen erweitert Grill-Sortiment am Point of Sale(23.09.2026 um 13:45 Uhr)
Windows Tipps & Security„When Worlds Unite“: ISE 2027 erweitert Messe und Programm(23.09.2026 um 13:45 Uhr)
Sichere ProgrammierungWhat Full-Stack AI Engineering Means in Real Projects(23.09.2026 um 14:00 Uhr)
Sichere ProgrammierungThe Internet Changes Everything (Slowly)(23.09.2026 um 14:09 Uhr)
Sichere ProgrammierungMAUI vs React Native vs Flutter vs Ionic(23.09.2026 um 14:09 Uhr)
Sichere ProgrammierungAI Tools Used in Modern Software Development(23.09.2026 um 14:22 Uhr)
Sichere ProgrammierungHealthAuditor — Website Health & SEO Audit Tool(23.09.2026 um 14:24 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

A Text and JSON Diff Viewer With LCS Algorithm and Semantic Comparison

A Text and JSON Diff Viewer With LCS Algorithm and Semantic Comparison Two JSON objects with the same keys in different order shouldn't show as "everything changed." This diff tool normalizes JSON (sorted keys, consistent formatting)…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!




A Text and JSON Diff Viewer With LCS Algorithm and Semantic Comparison




Two JSON objects with the same keys in different order shouldn't show as "everything changed." This diff tool normalizes JSON (sorted keys, consistent formatting) before comparing, so semantic equivalence produces zero diff. The diff engine itself is an LCS (Longest Common Subsequence) implementation — the same family of algorithms behind git diff.




Comparing text files is a solved problem in the terminal. But when you need to quickly paste two config files or API responses and see what changed, a browser tool with color coding is faster than firing up a terminal.



🔗 Live demo: https://sen.ltd/portfolio/diff-viewer/

📦 GitHub: https://github.com/sen-ltd/diff-viewer



Screenshot



Features:




  • 3 display modes: Unified, Side-by-side, Inline (word-level)

  • JSON-aware: normalizes key order before diffing

  • Stats: additions, deletions, changes

  • Copy diff in unified format

  • Japanese / English, dark / light theme

  • Zero dependencies, 39 tests





The LCS diff algorithm



The core is a standard LCS table between old and new line arrays:




  1. Build an (m+1)×(n+1) table where table[i][j] = length of LCS of old[0..i-1] and new[0..j-1]

  2. Backtrack from table[m][n] to produce edit operations

  3. Equal lines → type: 'equal', only in old → type: 'remove', only in new → type: 'add'



The time complexity is O(mn) where m and n are line counts. For typical config files and API responses (under 1000 lines), this runs in milliseconds.





JSON normalization



The key insight: {"a":1,"b":2} and {"b":2,"a":1} are semantically identical. Before diffing JSON, normalize both sides:




export function normalizeJSON(str) {
const obj = JSON.parse(str);
return JSON.stringify(obj, Object.keys(obj).sort(), 2);
}






Object.keys(obj).sort() as the replacer argument sorts keys alphabetically. Combined with indent of 2, both JSON objects produce identical strings — and the diff shows zero changes.






Inline word-level diff



The inline mode shows changes within lines. Instead of marking an entire line as changed, it highlights the specific words that differ:




export function computeInlineDiff(oldStr, newStr) {
const oldWords = oldStr.split(/(\s+)/);
const newWords = newStr.split(/(\s+)/);
// Same LCS algorithm, but on words instead of lines
}






Splitting on (\s+) (with capture group) preserves whitespace in the output, so the reconstructed text has correct spacing.






Tests



39 tests covering identical texts, complete replacement, middle insertion, JSON normalization, inline diff, stats computation, unified format output, and edge cases (empty input, single line, Unicode).






Series



This is entry #39 in my 100+ public portfolio series.



Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten A Text and JSON Diff Viewer With LCS Algorithm and Semantic Comparison

Thematisch verwandte Begriffe: Text, JSON, Diff, Viewer · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-5695 | Arbitrary file upload vulnerability due to a lack of proper validation in…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick