-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjson-diff.html
More file actions
861 lines (778 loc) Β· 44.6 KB
/
Copy pathjson-diff.html
File metadata and controls
861 lines (778 loc) Β· 44.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
<!DOCTYPE html>
<html lang="en">
<head>
<include src="_partials/meta-base.html"></include>
<title>JSON Diff β HTML Tools</title>
<meta name="description" content="Compare two JSON objects and instantly see what was added, removed, or changed. Runs in your browser β no installs, no servers, no tracking.">
<link rel="canonical" href="https://tools.mazipan.space/json-diff">
<meta property="og:title" content="JSON Diff β HTML Tools">
<meta property="og:description" content="Compare two JSON objects and instantly see what was added, removed, or changed. Runs in your browser β no installs, no servers, no tracking.">
<meta property="og:url" content="https://tools.mazipan.space/json-diff">
<meta name="twitter:title" content="JSON Diff β HTML Tools">
<meta name="twitter:description" content="Compare two JSON objects and instantly see what was added, removed, or changed. Runs in your browser β no installs, no servers, no tracking.">
<include src="_partials/meta-social.html"></include>
<link rel="icon" type="image/png" sizes="32x32" href="favicon-json-diff.png">
<include src="_partials/head-fonts.html"></include>
<link rel="stylesheet" href="styles.css">
<style>
.diff-added { background: rgba(63,185,80,.12); border-left: 3px solid #3fb950; }
.diff-removed { background: rgba(248,81,73,.12); border-left: 3px solid #f85149; }
.diff-changed { background: rgba(210,153,34,.12); border-left: 3px solid #d2991e; }
.badge-added { background: rgba(63,185,80,.15); color: #3fb950; }
.badge-removed { background: rgba(248,81,73,.15); color: #f85149; }
.badge-changed { background: rgba(210,153,34,.15); color: #d2991e; }
.val-old { color: #f85149; text-decoration: line-through; opacity: .8; }
.val-new { color: #3fb950; }
.val-add { color: #3fb950; }
.val-rem { color: #f85149; }
.diff-path { color: #c792ea; font-family: 'SFMono-Regular', Consolas, monospace; font-size: 0.78rem; }
/* Tree highlight rows */
.tree-hl-added { background: rgba(63,185,80,.15); border-radius: 3px; }
.tree-hl-removed { background: rgba(248,81,73,.15); border-radius: 3px; }
.tree-hl-changed { background: rgba(210,153,34,.15); border-radius: 3px; }
.tree-hl-parent { border-left: 2px solid rgba(255,255,255,.1); margin-left: 1px; }
mark.sh { background: #92400e; color: #fef3c7; border-radius: 2px; padding: 0 1px; }
mark.sh.sh-active { background: #f59e0b; color: #000; border-radius: 2px; padding: 0 1px; }
#search-input:-webkit-autofill,
#search-input:autofill {
-webkit-box-shadow: 0 0 0 1000px #111827 inset;
box-shadow: 0 0 0 1000px #111827 inset;
-webkit-text-fill-color: #e5e7eb;
caret-color: #e5e7eb;
}
</style>
<include src="_partials/head-theme.html"></include>
<!-- BEGIN:json-ld generated by scripts/generate-sections.mjs β re-run after editing tools.json -->
<script type="application/ld+json">{"@context":"https://schema.org","@type":"WebApplication","name":"JSON Diff","url":"https://tools.mazipan.space/json-diff","description":"Compare two JSON objects and instantly see what was added, removed, or changed. Runs in your browser β no installs, no servers, no tracking.","applicationCategory":"DeveloperApplication","operatingSystem":"Any","browserRequirements":"Requires JavaScript","offers":{"@type":"Offer","price":"0","priceCurrency":"USD"},"isPartOf":{"@type":"WebSite","name":"HTML Tools","url":"https://tools.mazipan.space/"}}</script>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"BreadcrumbList","itemListElement":[{"@type":"ListItem","position":1,"name":"HTML Tools","item":"https://tools.mazipan.space/"},{"@type":"ListItem","position":2,"name":"JSON Diff","item":"https://tools.mazipan.space/json-diff"}]}</script>
<script type="application/ld+json">{"@context":"https://schema.org","@type":"FAQPage","mainEntity":[{"@type":"Question","name":"Will whitespace or key-order differences show up?","acceptedAnswer":{"@type":"Answer","text":"No. Both inputs are normalized before diffing, so only real structural differences are highlighted."}},{"@type":"Question","name":"How are arrays compared?","acceptedAnswer":{"@type":"Answer","text":"By index. Reordering an array shows up as a removal-then-addition pair. Use JSON Sort first if you want order-insensitive comparison."}},{"@type":"Question","name":"Can it handle large JSON files?","acceptedAnswer":{"@type":"Answer","text":"Anything that fits comfortably in your browser memory. There's no hard limit; the diff updates as you type."}},{"@type":"Question","name":"Are there really no servers involved?","acceptedAnswer":{"@type":"Answer","text":"Right. The page is a single static HTML file; the comparison happens entirely in your browser."}}]}</script>
<!-- END:json-ld -->
</head>
<body class="bg-gray-950 text-gray-200 min-h-screen flex flex-col">
<include src="_partials/icons.html"></include>
<header class="border-b border-gray-800 px-6 py-4">
<nav aria-label="Breadcrumb" class="max-w-[1100px] mx-auto flex items-center gap-3">
<a href="index.html" class="no-underline text-white font-bold text-lg tracking-tight hover:text-blue-400 transition-colors">
HTML Tools
</a>
<span class="text-gray-700">/</span>
<span class="text-gray-400 text-sm" aria-current="page">π JSON Diff</span>
</nav>
</header>
<main class="max-w-[1100px] mx-auto w-full flex-1 py-8 px-6">
<header class="mb-7">
<h1 class="text-3xl font-bold text-white flex items-center gap-3">π JSON Diff</h1>
<p class="mt-1.5 text-sm text-gray-500">Paste two JSON objects then compare and inspect differences.</p>
</header>
<!-- Inputs -->
<div class="grid grid-cols-2 gap-4 mb-4 max-md:grid-cols-1">
<div>
<div class="flex items-center justify-between mb-2">
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wide">Original</label>
<span id="err-left" class="text-xs text-red-400"></span>
</div>
<textarea id="left" placeholder="Paste original JSON here..." spellcheck="false"
class="w-full h-64 rounded-lg border border-gray-700 bg-gray-900 text-gray-200
font-mono text-[0.8rem] leading-relaxed p-4 resize-y outline-none
focus:border-blue-400 transition-colors"></textarea>
</div>
<div>
<div class="flex items-center justify-between mb-2">
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wide">Modified</label>
<span id="err-right" class="text-xs text-red-400"></span>
</div>
<textarea id="right" placeholder="Paste modified JSON here..." spellcheck="false"
class="w-full h-64 rounded-lg border border-gray-700 bg-gray-900 text-gray-200
font-mono text-[0.8rem] leading-relaxed p-4 resize-y outline-none
focus:border-blue-400 transition-colors"></textarea>
</div>
</div>
<!-- Actions -->
<div class="flex flex-col gap-3 mb-6">
<label class="flex items-center gap-2 cursor-pointer select-none text-sm text-gray-400 hover:text-gray-200 transition-colors w-fit">
<input type="checkbox" id="show-tree"
class="w-4 h-4 rounded border-gray-600 bg-gray-800 accent-blue-400 cursor-pointer">
Reformat & show tree
</label>
<div class="flex items-center gap-2">
<button onclick="runCompare()" class="btn btn-primary">π Compare</button>
<button onclick="runReset()" class="btn btn-danger">β©οΈ Reset</button>
<button onclick="openSearch()" title="Search results (Ctrl+F / βF)" class="btn btn-secondary">π Search</button>
</div>
<!-- Search bar -->
<div id="search-bar" style="display:none"
class="flex items-center gap-1.5 px-2 py-1.5 rounded-lg border border-gray-700 bg-gray-900/70 w-full max-w-lg">
<input id="search-input" type="text" placeholder="Search in resultsβ¦" spellcheck="false" autocomplete="off"
oninput="runSearch()"
onkeydown="onSearchKey(event)"
class="flex-1 bg-transparent text-gray-200 font-mono text-[0.78rem] outline-none placeholder-gray-600 min-w-0">
<span id="search-count" class="text-[0.7rem] text-gray-500 whitespace-nowrap select-none"></span>
<button onclick="navigateSearch(-1)" title="Previous (Shift+Enter)" class="btn-icon btn-icon-sm ghost"><svg class="icon" aria-hidden="true"><use href="#icon-arrow-up"/></svg></button>
<button onclick="navigateSearch(1)" title="Next (Enter)" class="btn-icon btn-icon-sm ghost"><svg class="icon" aria-hidden="true"><use href="#icon-arrow-down"/></svg></button>
<button onclick="closeSearch()" title="Close (Esc)" class="btn-icon btn-icon-sm danger"><svg class="icon" aria-hidden="true"><use href="#icon-x"/></svg></button>
</div>
</div>
<!-- Diff result -->
<div id="diff-section" style="display:none" class="mb-6"></div>
<!-- Tree section -->
<div id="tree-section" style="display:none">
<div class="flex items-center gap-4 flex-wrap mb-3">
<span class="text-xs text-gray-500 font-medium uppercase tracking-wide">Legend</span>
<span class="flex items-center gap-1.5 text-xs text-gray-400">
<span class="inline-block w-3 h-3 rounded-sm" style="background:rgba(63,185,80,.4); border-left: 3px solid #3fb950"></span>
Added
</span>
<span class="flex items-center gap-1.5 text-xs text-gray-400">
<span class="inline-block w-3 h-3 rounded-sm" style="background:rgba(248,81,73,.4); border-left: 3px solid #f85149"></span>
Removed
</span>
<span class="flex items-center gap-1.5 text-xs text-gray-400">
<span class="inline-block w-3 h-3 rounded-sm" style="background:rgba(210,153,34,.4); border-left: 3px solid #d2991e"></span>
Changed
</span>
<span class="flex items-center gap-1.5 text-xs text-gray-400">
<span class="inline-block w-3 h-3 rounded-sm border-l-2 border-white/10 bg-transparent"></span>
Has changes inside
</span>
<label class="flex items-center gap-1.5 text-xs text-gray-400 hover:text-gray-200 cursor-pointer select-none ml-auto">
<input type="checkbox" id="lock-scroll" checked
class="w-3.5 h-3.5 accent-blue-400 cursor-pointer">
Lock scroll
</label>
</div>
<div class="grid grid-cols-2 gap-4 max-md:grid-cols-1">
<div>
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wide block mb-2">Original β Tree</label>
<div id="left-tree"
class="w-full h-96 rounded-lg border border-gray-700 bg-gray-900
font-mono text-[0.8rem] leading-relaxed p-4 overflow-auto resize-y"></div>
</div>
<div>
<label class="text-xs font-semibold text-gray-500 uppercase tracking-wide block mb-2">Modified β Tree</label>
<div id="right-tree"
class="w-full h-96 rounded-lg border border-gray-700 bg-gray-900
font-mono text-[0.8rem] leading-relaxed p-4 overflow-auto resize-y"></div>
</div>
</div>
</div>
</main>
<section class="max-w-[1100px] mx-auto w-full px-6 py-8 border-t border-gray-800">
<div class="grid gap-6 md:grid-cols-2">
<div>
<h2 class="text-xl font-bold text-white mb-4">About JSON Diff</h2>
<p class="text-gray-400 leading-relaxed">Paste two JSON objects to instantly see what was added, removed, or changed. Differences are color-coded inline so you can scan at a glance β green for additions, red for removals, amber for modifications.</p>
</div>
<div>
<h2 class="text-xl font-bold text-white mb-4">How to use</h2>
<ol class="text-gray-400 leading-relaxed space-y-2 list-decimal list-inside">
<li>Paste the original JSON in the left panel.</li>
<li>Paste the updated version in the right panel.</li>
<li>Review the inline diff; toggle <strong class="text-gray-300">show unchanged</strong> if you want surrounding context.</li>
<li>Use the badges in the header to jump between change types.</li>
</ol>
</div>
<div>
<h2 class="text-xl font-bold text-white mb-4">Common use cases</h2>
<ul class="text-gray-400 leading-relaxed space-y-2 list-disc list-inside">
<li>Comparing API responses before and after a code change.</li>
<li>Reviewing what changed in a configuration file across environments.</li>
<li>Verifying that a serialization round-trip preserved every field.</li>
<li>Catching unintended additions or removals during a refactor.</li>
</ul>
</div>
<div>
<h2 class="text-xl font-bold text-white mb-4">Tips</h2>
<ul class="text-gray-400 leading-relaxed space-y-2 list-disc list-inside">
<li>Whitespace and key-order differences never show up β inputs are normalized before diffing.</li>
<li>Arrays diff by index, so a reorder shows as a removal-then-addition pair.</li>
<li>The diff updates as you type; no button to click.</li>
</ul>
</div>
</div>
</section>
<!-- BEGIN:faq generated by scripts/generate-sections.mjs β re-run after editing tools.json -->
<section class="max-w-[1100px] mx-auto w-full px-6 py-8 border-t border-gray-800">
<h2 class="text-xl font-bold text-white mb-6">FAQ</h2>
<div class="space-y-2">
<details class="disclosure">
<summary>Will whitespace or key-order differences show up?</summary>
<div class="disclosure-content"><div class="disclosure-body">No. Both inputs are normalized before diffing, so only real structural differences are highlighted.</div></div>
</details>
<details class="disclosure">
<summary>How are arrays compared?</summary>
<div class="disclosure-content"><div class="disclosure-body">By index. Reordering an array shows up as a removal-then-addition pair. Use JSON Sort first if you want order-insensitive comparison.</div></div>
</details>
<details class="disclosure">
<summary>Can it handle large JSON files?</summary>
<div class="disclosure-content"><div class="disclosure-body">Anything that fits comfortably in your browser memory. There's no hard limit; the diff updates as you type.</div></div>
</details>
<details class="disclosure">
<summary>Are there really no servers involved?</summary>
<div class="disclosure-content"><div class="disclosure-body">Right. The page is a single static HTML file; the comparison happens entirely in your browser.</div></div>
</details>
</div>
</section>
<!-- END:faq -->
<!-- BEGIN:more-tools generated by scripts/generate-sections.mjs β re-run after editing tools.json -->
<section class="max-w-[1100px] mx-auto w-full px-6 py-8 border-t border-gray-800">
<h2 class="text-xl font-bold text-white mb-6">More tools</h2>
<div class="space-y-4">
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">JSON</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/json-formatter" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">ποΈ JSON Formatter</a>
<a href="/json-to-ts" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π· JSON to TypeScript</a>
<a href="/json-sort" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π€ JSON Sort</a>
<a href="/csv-to-json" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π JSON β CSV</a>
<a href="/json-to-yaml" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π JSON β YAML</a>
<a href="/json-to-schema" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π‘οΈ JSON to Validator Schema</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Code</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/regex-tester" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π§ͺ Regex Tester</a>
<a href="/svg-to-jsx" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">βοΈ SVG to JSX</a>
<a href="/svg-rasterizer" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π· SVG to Raster</a>
<a href="/cron-decoder" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">β±οΈ Cron Decoder</a>
<a href="/snippet-to-image" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πΈ Code Snippet to Image</a>
<a href="/text-diff" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Text Diff</a>
<a href="/markdown-preview" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Markdown Preview</a>
<a href="/semver-checker" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π·οΈ SemVer Checker</a>
<a href="/jwt-decoder" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π JWT Decoder</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Ornaments</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/gradients" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π¨ Gradients</a>
<a href="/blob" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π«§ Blob Generator</a>
<a href="/waves" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">γ°οΈ Wave Generator</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Image</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/image-compressor" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">ποΈ Image Compressor</a>
<a href="/image-resizer" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Image Resizer</a>
<a href="/image-cropper" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">βοΈ Image Cropper</a>
<a href="/image-converter" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πΌοΈ Image Format Converter</a>
<a href="/image-watermark" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Image Watermark</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Audio</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/mp3-tag-editor" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π΅ MP3 Tag Editor</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Web / SEO</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/meta-tag-preview" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Meta Tag Preview</a>
<a href="/user-agent-parser" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π΅οΈ User Agent Parser</a>
<a href="/og-image-builder" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πΌοΈ OG Image Builder</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Generators</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/qr-code-generator" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π± QR Code Generator</a>
<a href="/lorem-ipsum" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Lorem Ipsum Generator</a>
<a href="/avatar-generator" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π€ Avatar Generator</a>
<a href="/favicon-generator" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">β Favicon Generator</a>
<a href="/uuid-generator" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πͺͺ UUID Generator</a>
<a href="/wheel-of-names" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π‘ Wheel of Names</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">PDF</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/pdf-merger" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π PDF Merger</a>
<a href="/image-to-pdf" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π Image to PDF</a>
<a href="/pdf-compressor" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π€ PDF Compressor</a>
<a href="/pdf-splitter" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">βοΈ PDF Splitter</a>
<a href="/pdf-page-manager" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">ποΈ PDF Page Manager</a>
<a href="/pdf-watermark" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π§ PDF Watermark</a>
<a href="/pdf-signature" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">βοΈ PDF Signature</a>
<a href="/pdf-to-image" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">πΌοΈ PDF to Image</a>
</div>
</div>
<div>
<h3 class="text-xs font-semibold uppercase tracking-wider text-gray-500 mb-2">Time</h3>
<div class="flex flex-wrap gap-x-5 gap-y-2">
<a href="/pomodoro-timer" class="text-sm text-gray-300 hover:text-blue-400 transition-colors no-underline">π
Pomodoro Timer</a>
</div>
</div>
</div>
</section>
<!-- END:more-tools -->
<footer class="max-w-[1100px] mx-auto w-full py-8 px-6 border-t border-gray-800 text-center text-sm text-gray-600">
<div>© <span id="year"></span> <a href="https://mazipan.space" rel="noreferrer noopener" target="_blank" class="text-blue-400 transition-colors">Irfan Maulana</a> & Claude</div>
<div><span id="deploy-time"></span></div>
<div><span id="commit-sha"></span><a href="https://github.com/mazipan/html-tools" rel="noreferrer noopener" target="_blank" class="text-blue-400 transition-colors">Source</a></div>
<div><a href="design-system.html" rel="nofollow" class="text-blue-400 transition-colors">Design system</a></div>
<div><a href="https://baca-quran.id" rel="noreferrer noopener" target="_blank" class="text-blue-400 transition-colors">Baca Quran</a> Β· <a href="https://games.mazipan.space" rel="noreferrer noopener" target="_blank" class="text-blue-400 transition-colors">Games</a></div>
</footer>
<script src="json-utils.js"></script>
<include src="_partials/footer-script.html"></include>
<script>
const leftEl = document.getElementById('left');
const rightEl = document.getElementById('right');
const errLeft = document.getElementById('err-left');
const errRight = document.getElementById('err-right');
const treeSection = document.getElementById('tree-section');
const diffSection = document.getElementById('diff-section');
const leftTreeEl = document.getElementById('left-tree');
const rightTreeEl = document.getElementById('right-tree');
const showTreeCb = document.getElementById('show-tree');
let lastChanges = null;
let isSyncing = false;
function setupScrollSync() {
function sync(source, target) {
source.addEventListener('scroll', () => {
if (!document.getElementById('lock-scroll').checked || isSyncing) return;
isSyncing = true;
target.scrollTop = source.scrollTop;
target.scrollLeft = source.scrollLeft;
requestAnimationFrame(() => { isSyncing = false; });
});
}
sync(leftTreeEl, rightTreeEl);
sync(rightTreeEl, leftTreeEl);
}
setupScrollSync();
// ββ Helpers βββββββββββββββββββββββββββββββββββββββββββββββββββ
function escHtml(s) {
return String(s).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"').replace(/'/g,''');
}
function clearErrors() {
errLeft.textContent = '';
errRight.textContent = '';
leftEl.classList.remove('border-red-500');
rightEl.classList.remove('border-red-500');
}
function parseBoth() {
clearErrors();
let left, right, ok = true;
try { ({ value: left } = tolerantParse(leftEl.value.trim())); }
catch(e) { errLeft.textContent = e.message; leftEl.classList.add('border-red-500'); ok = false; }
try { ({ value: right } = tolerantParse(rightEl.value.trim())); }
catch(e) { errRight.textContent = e.message; rightEl.classList.add('border-red-500'); ok = false; }
return ok ? { left, right } : null;
}
// ββ Actions βββββββββββββββββββββββββββββββββββββββββββββββββββ
function runCompare() {
const data = parseBoth();
if (!data) return;
lastChanges = computeDiff(data.left, data.right);
const added = lastChanges.filter(c => c.type === 'added').length;
const removed = lastChanges.filter(c => c.type === 'removed').length;
const changed = lastChanges.filter(c => c.type === 'changed').length;
diffSection.style.display = '';
diffSection.innerHTML = renderSummary(added, removed, changed) + renderChanges(lastChanges);
if (showTreeCb.checked) {
refreshTrees(data);
} else {
treeSection.style.display = 'none';
}
}
function refreshTrees(data) {
// Reformat textareas
leftEl.value = JSON.stringify(data.left, null, 2);
rightEl.value = JSON.stringify(data.right, null, 2);
// Build per-side highlight maps from last diff
const leftHL = new Map();
const rightHL = new Map();
if (lastChanges) {
for (const c of lastChanges) {
if (c.type === 'removed' || c.type === 'changed') leftHL.set(c.path, c.type);
if (c.type === 'added' || c.type === 'changed') rightHL.set(c.path, c.type);
}
}
treeSection.style.display = '';
renderTreeInto(leftTreeEl, data.left, leftHL);
renderTreeInto(rightTreeEl, data.right, rightHL);
leftTreeEl.scrollTop = 0;
rightTreeEl.scrollTop = 0;
}
function runReset() {
leftEl.value = '';
rightEl.value = '';
clearErrors();
lastChanges = null;
showTreeCb.checked = false;
treeSection.style.display = 'none';
diffSection.style.display = 'none';
diffSection.innerHTML = '';
leftTreeEl.innerHTML = '';
rightTreeEl.innerHTML = '';
closeSearch();
leftEl.focus();
}
// ββ Tree renderer βββββββββββββββββββββββββββββββββββββββββββββ
function renderTreeInto(container, value, highlights) {
container.innerHTML = '';
const root = document.createElement('div');
root.className = 'tree-root';
const counter = { n: 1 };
root.appendChild(buildTree(value, null, true, false, '', highlights, counter));
container.appendChild(root);
}
function childPath(parentPath, key, isArrayItem) {
if (key === null) return parentPath;
if (isArrayItem) return parentPath ? `${parentPath}[${key}]` : `[${key}]`;
return parentPath ? `${parentPath}.${key}` : String(key);
}
function hasDescendant(path, highlights) {
if (!highlights.size) return false;
const prefix = path ? path + '.' : '';
const prefixArr = path ? path + '[' : '[';
for (const [p] of highlights) {
if (p.startsWith(prefix) || p.startsWith(prefixArr)) return true;
}
return false;
}
function buildTree(value, key, isLast, isArrayItem, parentPath, highlights, counter) {
const curPath = childPath(parentPath, key, isArrayItem);
const hlType = highlights?.get(curPath);
const hasDesc = !hlType && highlights?.size && hasDescendant(curPath, highlights);
const node = document.createElement('div');
node.className = 'tree-node';
if (value === null || typeof value !== 'object') {
const row = document.createElement('div');
row.className = 'tree-row' + (hlType ? ` tree-hl-${hlType}` : '');
row.dataset.path = curPath;
row.innerHTML =
`<span class="line-num">${counter.n++}</span>` +
'<span class="toggle-btn leaf">βΆ</span>' +
(key !== null && !isArrayItem ? `<span class="json-key">"${escHtml(String(key))}"</span><span class="json-punct">: </span>` : '') +
primitiveHtml(value) +
(isLast ? '' : '<span class="tree-comma">,</span>');
node.appendChild(row);
return node;
}
const isArray = Array.isArray(value);
const keys = isArray ? value.map((_, i) => i) : Object.keys(value);
const openB = isArray ? '[' : '{';
const closeB = isArray ? ']' : '}';
const preview = `${keys.length} ${isArray ? 'item' : 'key'}${keys.length !== 1 ? 's' : ''}`;
const headerRow = document.createElement('div');
headerRow.className = 'tree-row' + (hlType ? ` tree-hl-${hlType}` : hasDesc ? ' tree-hl-parent' : '');
headerRow.dataset.path = curPath;
headerRow.style.cursor = 'pointer';
const toggleBtn = document.createElement('span');
toggleBtn.className = 'toggle-btn';
toggleBtn.textContent = 'βΌ';
const keyHtml = key !== null && !isArrayItem
? `<span class="json-key">"${escHtml(String(key))}"</span><span class="json-punct">: </span>`
: '';
headerRow.innerHTML =
`<span class="line-num">${counter.n++}</span>` +
keyHtml +
`<span class="json-punct">${openB}</span>` +
`<span class="collapsed-preview" style="display:none"> ${preview} </span>`;
headerRow.insertBefore(toggleBtn, headerRow.children[1]);
node.appendChild(headerRow);
const childrenEl = document.createElement('div');
childrenEl.className = 'tree-children';
keys.forEach((k, i) => {
childrenEl.appendChild(
buildTree(value[k], k, i === keys.length - 1, isArray, curPath, highlights, counter)
);
});
node.appendChild(childrenEl);
const footerRow = document.createElement('div');
footerRow.className = 'tree-row';
footerRow.innerHTML =
`<span class="line-num">${counter.n++}</span>` +
'<span class="toggle-btn leaf">βΆ</span>' +
`<span class="json-punct">${closeB}</span>` +
(isLast ? '' : '<span class="tree-comma">,</span>');
node.appendChild(footerRow);
const collapsedPreview = headerRow.querySelector('.collapsed-preview');
let collapsed = false;
toggleBtn.addEventListener('click', e => {
e.stopPropagation();
collapsed = !collapsed;
toggleBtn.textContent = collapsed ? 'βΆ' : 'βΌ';
childrenEl.style.display = collapsed ? 'none' : '';
footerRow.style.display = collapsed ? 'none' : '';
collapsedPreview.style.display = collapsed ? 'inline' : 'none';
if (collapsed) collapsedPreview.textContent = ` ${preview} ${closeB}${isLast ? '' : ','}`;
});
headerRow.addEventListener('click', () => toggleBtn.click());
return node;
}
function primitiveHtml(v) {
if (v === null) return `<span class="json-null">null</span>`;
if (typeof v === 'boolean') return `<span class="json-bool">${v}</span>`;
if (typeof v === 'number') return `<span class="json-number">${v}</span>`;
return `<span class="json-string">"${escHtml(v)}"</span>`;
}
// ββ Diff algorithm βββββββββββββββββββββββββββββββββββββββββββββ
function computeDiff(a, b, path = '') {
if (a === b) return [];
const typeA = Array.isArray(a) ? 'array' : (a === null ? 'null' : typeof a);
const typeB = Array.isArray(b) ? 'array' : (b === null ? 'null' : typeof b);
if (typeA !== typeB || (typeA !== 'object' && typeA !== 'array')) {
return [{ type: 'changed', path, oldVal: a, newVal: b }];
}
const changes = [];
if (typeA === 'array') {
const len = Math.max(a.length, b.length);
for (let i = 0; i < len; i++) {
const p = `${path}[${i}]`;
if (i >= a.length) changes.push({ type: 'added', path: p, newVal: b[i] });
else if (i >= b.length) changes.push({ type: 'removed', path: p, oldVal: a[i] });
else changes.push(...computeDiff(a[i], b[i], p));
}
} else {
for (const key of new Set([...Object.keys(a), ...Object.keys(b)])) {
const p = path ? `${path}.${key}` : key;
if (!(key in a)) changes.push({ type: 'added', path: p, newVal: b[key] });
else if (!(key in b)) changes.push({ type: 'removed', path: p, oldVal: a[key] });
else changes.push(...computeDiff(a[key], b[key], p));
}
}
return changes;
}
// ββ Diff rendering βββββββββββββββββββββββββββββββββββββββββββββ
function shortVal(v) {
if (v === null) return 'null';
if (typeof v !== 'object') return JSON.stringify(v);
const s = JSON.stringify(v);
return s.length > 60 ? s.slice(0, 57) + 'β¦' : s;
}
function renderSummary(added, removed, changed) {
if (added + removed + changed === 0) {
return `<div class="flex items-center gap-2 text-green-400 text-sm font-medium py-4">
<span class="text-lg">β</span> Both JSON objects are identical.
</div>`;
}
return `
<div class="grid grid-cols-3 gap-3 mb-4 max-sm:grid-cols-1">
<div class="badge-added rounded-lg px-4 py-3 flex items-center gap-3">
<span class="text-2xl font-bold">${added}</span>
<div>
<div class="text-xs font-semibold uppercase tracking-wide opacity-70">Added</div>
<div class="text-xs opacity-60">new ${added === 1 ? 'field' : 'fields'}</div>
</div>
</div>
<div class="badge-removed rounded-lg px-4 py-3 flex items-center gap-3">
<span class="text-2xl font-bold">${removed}</span>
<div>
<div class="text-xs font-semibold uppercase tracking-wide opacity-70">Removed</div>
<div class="text-xs opacity-60">deleted ${removed === 1 ? 'field' : 'fields'}</div>
</div>
</div>
<div class="badge-changed rounded-lg px-4 py-3 flex items-center gap-3">
<span class="text-2xl font-bold">${changed}</span>
<div>
<div class="text-xs font-semibold uppercase tracking-wide opacity-70">Changed</div>
<div class="text-xs opacity-60">modified ${changed === 1 ? 'value' : 'values'}</div>
</div>
</div>
</div>`;
}
function renderChanges(changes) {
if (!changes.length) return '';
return `<div class="flex flex-col gap-1">${changes.map(c => {
let valueHtml;
if (c.type === 'added') {
valueHtml = `<span class="val-add">${escHtml(shortVal(c.newVal))}</span>`;
} else if (c.type === 'removed') {
valueHtml = `<span class="val-rem">${escHtml(shortVal(c.oldVal))}</span>`;
} else {
valueHtml = `<span class="val-old">${escHtml(shortVal(c.oldVal))}</span>
<span class="text-gray-600 mx-1">β</span>
<span class="val-new">${escHtml(shortVal(c.newVal))}</span>`;
}
const icon = c.type === 'added' ? '+' : c.type === 'removed' ? 'β' : 'β ';
const iconColor = c.type === 'added' ? 'text-green-400' : c.type === 'removed' ? 'text-red-400' : 'text-yellow-500';
return `
<div class="diff-${c.type} rounded px-3 py-2 flex items-baseline gap-3 flex-wrap cursor-pointer hover:brightness-125 transition-all"
data-diff-path="${escHtml(c.path || '')}" onclick="scrollToPath(this.dataset.diffPath)" title="Click to scroll to this path in the tree">
<span class="w-5 text-center font-bold font-mono text-xs ${iconColor}">${icon}</span>
<span class="diff-path">${escHtml(c.path || '(root)')}</span>
<span class="text-gray-600 text-xs">${c.type}</span>
<span class="ml-auto font-mono text-xs text-right">${valueHtml}</span>
</div>`;
}).join('')}</div>`;
}
// ββ Scroll to path βββββββββββββββββββββββββββββββββββββββββββ
function isAncestorPath(ancestor, target) {
return target === ancestor || target.startsWith(ancestor + '.') || target.startsWith(ancestor + '[');
}
function scrollToPath(path) {
if (treeSection.style.display === 'none') return;
// Expand only ancestors of the target path, leaving everything else as-is
[leftTreeEl, rightTreeEl].forEach(container => {
container.querySelectorAll('.toggle-btn:not(.leaf)').forEach(btn => {
if (btn.textContent !== 'βΆ') return;
const row = btn.closest('[data-path]');
if (row && isAncestorPath(row.dataset.path, path)) btn.click();
});
});
[leftTreeEl, rightTreeEl].forEach(container => {
const rows = container.querySelectorAll('[data-path]');
const row = Array.from(rows).find(r => r.dataset.path === path);
if (!row) return;
row.scrollIntoView({ block: 'center', behavior: 'smooth' });
row.style.outline = '2px solid #f59e0b';
row.style.borderRadius = '3px';
setTimeout(() => { row.style.outline = ''; row.style.borderRadius = ''; }, 1200);
});
}
// ββ Search βββββββββββββββββββββββββββββββββββββββββββββββββββ
let searchMatches = [];
let searchCurrent = -1;
let searchCollapsedSnapshot = null;
function captureCollapsed() {
const snap = { left: new Set(), right: new Set() };
[[leftTreeEl, 'left'], [rightTreeEl, 'right']].forEach(([container, side]) => {
container.querySelectorAll('.toggle-btn:not(.leaf)').forEach(btn => {
if (btn.textContent === 'βΆ') {
const row = btn.closest('[data-path]');
if (row) snap[side].add(row.dataset.path);
}
});
});
return snap;
}
function restoreCollapsed(snap) {
[[leftTreeEl, 'left'], [rightTreeEl, 'right']].forEach(([container, side]) => {
container.querySelectorAll('.toggle-btn:not(.leaf)').forEach(btn => {
if (btn.textContent === 'βΌ') {
const row = btn.closest('[data-path]');
if (row && snap[side].has(row.dataset.path)) btn.click();
}
});
});
}
function openSearch() {
const bar = document.getElementById('search-bar');
bar.style.display = 'flex';
document.getElementById('search-input').select();
document.getElementById('search-input').focus();
if (!searchCollapsedSnapshot) searchCollapsedSnapshot = captureCollapsed();
}
function closeSearch() {
const bar = document.getElementById('search-bar');
if (!bar) return;
bar.style.display = 'none';
clearSearchHighlights();
searchMatches = [];
searchCurrent = -1;
document.getElementById('search-count').textContent = '';
if (searchCollapsedSnapshot) {
restoreCollapsed(searchCollapsedSnapshot);
searchCollapsedSnapshot = null;
}
}
function clearSearchHighlights() {
[diffSection, leftTreeEl, rightTreeEl].forEach(container => {
container.querySelectorAll('mark.sh').forEach(mark => {
const parent = mark.parentNode;
if (parent) {
parent.replaceChild(document.createTextNode(mark.textContent), mark);
parent.normalize();
}
});
});
}
function getTextNodes(container) {
const results = [];
const walker = document.createTreeWalker(container, NodeFilter.SHOW_TEXT, {
acceptNode(node) {
if (node.parentElement && node.parentElement.classList.contains('line-num')) {
return NodeFilter.FILTER_REJECT;
}
return NodeFilter.FILTER_ACCEPT;
}
});
let node;
while ((node = walker.nextNode())) results.push(node);
return results;
}
function runSearch() {
clearSearchHighlights();
searchMatches = [];
searchCurrent = -1;
const query = document.getElementById('search-input').value;
const countEl = document.getElementById('search-count');
if (!query) { countEl.textContent = ''; return; }
// Snapshot collapsed state (if not already), then expand all so every node is searchable
if (!searchCollapsedSnapshot) searchCollapsedSnapshot = captureCollapsed();
[leftTreeEl, rightTreeEl].forEach(container => {
container.querySelectorAll('.toggle-btn:not(.leaf)').forEach(btn => {
if (btn.textContent === 'βΆ') btn.click();
});
});
const lowerQuery = query.toLowerCase();
const containers = [diffSection, leftTreeEl, rightTreeEl].filter(
el => el.style.display !== 'none' && el.innerHTML
);
containers.forEach(container => {
getTextNodes(container).forEach(textNode => {
const text = textNode.textContent;
const lowerText = text.toLowerCase();
let idx = lowerText.indexOf(lowerQuery);
if (idx === -1) return;
const frag = document.createDocumentFragment();
let lastIdx = 0;
while (idx !== -1) {
if (idx > lastIdx) frag.appendChild(document.createTextNode(text.slice(lastIdx, idx)));
const mark = document.createElement('mark');
mark.className = 'sh';
mark.textContent = text.slice(idx, idx + query.length);
frag.appendChild(mark);
searchMatches.push(mark);
lastIdx = idx + query.length;
idx = lowerText.indexOf(lowerQuery, lastIdx);
}
if (lastIdx < text.length) frag.appendChild(document.createTextNode(text.slice(lastIdx)));
textNode.parentNode.replaceChild(frag, textNode);
});
});
if (searchMatches.length === 0) {
countEl.textContent = 'No matches';
countEl.className = 'text-[0.7rem] text-red-400 whitespace-nowrap select-none';
return;
}
countEl.className = 'text-[0.7rem] text-gray-500 whitespace-nowrap select-none';
searchCurrent = 0;
updateSearchActive();
}
function updateSearchActive() {
searchMatches.forEach((m, i) => {
m.className = i === searchCurrent ? 'sh sh-active' : 'sh';
});
const active = searchMatches[searchCurrent];
if (active) active.scrollIntoView({ block: 'center', behavior: 'smooth' });
document.getElementById('search-count').textContent =
`${searchCurrent + 1} / ${searchMatches.length}`;
}
function navigateSearch(dir) {
if (searchMatches.length === 0) return;
searchCurrent = (searchCurrent + dir + searchMatches.length) % searchMatches.length;
updateSearchActive();
}
function onSearchKey(e) {
if (e.key === 'Enter') {
e.preventDefault();
navigateSearch(e.shiftKey ? -1 : 1);
} else if (e.key === 'Escape') {
closeSearch();
}
}
document.addEventListener('keydown', (e) => {
if ((e.ctrlKey || e.metaKey) && e.key === 'f') {
e.preventDefault();
openSearch();
}
});
leftEl.focus();
</script>
</body>
</html>