Spaces:
Running
Running
File size: 9,107 Bytes
917edd2 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 | <!doctype html><html lang="en"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>JSON Shape Diff</title><style>
*{box-sizing:border-box}body{margin:0;background:#f4f3ef;color:#172b32;font:16px system-ui,sans-serif}main{max-width:1160px;margin:auto;padding:44px 24px}h1{font-size:clamp(36px,7vw,62px);letter-spacing:-2px;margin:10px 0}h2{font-size:23px}.eyebrow{font-size:12px;font-weight:750;letter-spacing:3px;color:#41765d}.lead{font-size:19px;line-height:1.55;max-width:780px;color:#52646b}.note{padding:16px 20px;border-left:4px solid #ba783b;background:#fff7e8;line-height:1.6}.inputs{display:grid;grid-template-columns:1fr 1fr;gap:20px;margin-top:26px}.panel{min-width:0}label.title{font-weight:700;display:block;margin-bottom:10px}textarea{width:100%;min-height:260px;resize:vertical;border:1px solid #a8b9b7;background:white;border-radius:10px;padding:16px;font:14px/1.6 ui-monospace,monospace;color:#172b32}button,.file{border:0;border-radius:7px;padding:12px 17px;background:#255d49;color:white;font:600 14px system-ui;cursor:pointer;display:inline-block}button.alt,.file{background:#e0e8e1;color:#244d3e}.controls{display:flex;align-items:center;flex-wrap:wrap;gap:12px;margin:20px 0}.small{font-size:13px;line-height:1.65;color:#5c6d72}.file input{display:none}input[type=search],select{padding:10px;border:1px solid #a8b9b7;border-radius:7px;font:inherit;background:white;max-width:100%}input[type=checkbox]{accent-color:#255d49}.scroll{overflow:auto;border:1px solid #bbc9c4;border-radius:10px}table{border-collapse:collapse;text-align:left;width:100%;min-width:650px;font-size:14px}td,th{padding:13px 15px;border-bottom:1px solid #dce3df;vertical-align:top}th{background:#e4ebe6}td{overflow-wrap:anywhere;max-width:400px}code{font:13px ui-monospace,monospace;white-space:pre-wrap;overflow-wrap:anywhere}#summary{font-size:20px;font-weight:700}#status{min-height:23px}.error{color:#a63f25}footer{margin-top:32px;border-top:1px solid #ccd5cf;padding-top:22px}.badge{font-size:12px;font-weight:650;white-space:nowrap}a{color:#255d49}:focus-visible{outline:3px solid #bb7437;outline-offset:3px}@media(max-width:650px){main{padding:26px 16px}.inputs{grid-template-columns:1fr}textarea{min-height:210px}}
</style></head><body><main><div class="eyebrow">SMALL TOOLS / LOCAL DATA</div><h1>What changed in this JSON?</h1><p class="lead">Compare two payloads without sending them to an AI. Find added keys, missing values, type changes and exact value differences.</p><div class="note"><strong>Local comparison, explicit limits.</strong> Arrays are compared by index, not matched by ID. Moving an array item can look like several changes. This is not schema validation, a security scan or a semantic comparison.</div>
<div class="inputs"><section class="panel"><label for="before" class="title">Before</label><textarea id="before" spellcheck="false" aria-label="Before JSON"></textarea><div class="controls"><label class="file">Open before file<input id="before-file" type="file" accept=".json,application/json"></label></div></section><section class="panel"><label for="after" class="title">After</label><textarea id="after" spellcheck="false" aria-label="After JSON"></textarea><div class="controls"><label class="file">Open after file<input id="after-file" type="file" accept=".json,application/json"></label></div></section></div>
<div class="controls"><button id="compare">Compare JSON</button><button id="sample" class="alt">Load synthetic example</button><button id="clear" class="alt">Clear inputs</button><label><input id="values" type="checkbox"> Include actual values in view and export</label></div>
<p class="small">Values are hidden by default. Paths and types can still reveal private details. Maximum 500KB per input, 20,000 nodes, 80 nesting levels and 3,000 reported changes. Numbers use JavaScript precision; unsafe parsed integers and non-finite values are rejected. Decimal rounding still applies. Duplicate object keys are resolved by JSON.parse to the final value.</p>
<p id="status" class="small" role="status" aria-live="polite"></p><h2 id="summary">Ready to compare</h2><div class="controls"><label>Operation <select id="filter"><option value="">All changes</option><option value="added">Added</option><option value="removed">Removed</option><option value="type_changed">Type changed</option><option value="value_changed">Value changed</option></select></label><input id="search" type="search" placeholder="Search JSON Pointer path" aria-label="Search path"><button id="download" class="alt" disabled>Download report</button></div><p class="small" id="count"></p><div class="scroll"><table><thead><tr><th>Change</th><th>JSON Pointer path</th><th>Before</th><th>After</th></tr></thead><tbody id="rows"></tbody></table></div>
<p class="small">The empty path means the document root. Keys containing / or ~ use JSON Pointer escaping (~1 and ~0). Removed/added containers are one change, not a separate row for every descendant. Object key order is ignored; string content and array positions are not.</p>
<footer class="small">Built with AI assistance for Vitali Pavlovski. MIT license. All bundled examples are synthetic. This app has no analytics, external libraries or model API calls. Files and pasted text are processed in your browser, not uploaded by this app. Ordinary page requests still reach the hosting platform. Data stays in page memory until cleared or closed; downloads are your responsibility. Browser extensions may have their own access.<br><a href="diff.js" download>Download comparison engine</a> · <a href="tests.cjs" download>Download engine tests</a></footer></main><script src="diff.js"></script><script>
'use strict';const $=id=>document.getElementById(id);let result=null;const samples=[{service:'demo',retries:2,active:true,owner:null,items:[{id:'a',cost:10}]},{service:'demo',retries:'2',active:false,timeout:30,items:[{id:'a',cost:12},{id:'b',cost:5}]}];
function invalidate(){result=null;$('rows').replaceChildren();$('summary').textContent='Inputs changed - compare again';$('count').textContent='';$('download').disabled=true;}
function loadSample(){[0,1].forEach((n)=>$(n?'after':'before').value=JSON.stringify(samples[n],null,2));invalidate();$('status').textContent='Synthetic example loaded. No real accounts or customer data.';}
function cell(value){const td=document.createElement('td');const c=document.createElement('code');c.textContent=value;td.append(c);return td;}
function display(row,side){const k=side+'_type';if(row[k]==='missing')return '(missing)';if(!result.values_included)return row[k];return JSON.stringify(row[side],null,2);}
function render(){if(!result)return;const rows=result.changes.filter(r=>(!$('filter').value||r.operation===$('filter').value)&&r.path.toLowerCase().includes($('search').value.toLowerCase()));$('rows').replaceChildren();for(const r of rows.slice(0,300)){const tr=document.createElement('tr');tr.append(cell(r.operation),cell(r.path||'(root)'),cell(display(r,'before')),cell(display(r,'after')));$('rows').append(tr);}$('count').textContent=rows.length+' matching changes. Showing up to 300; export includes the entire report, not just this filter.';}
$('compare').onclick=()=>{invalidate();try{const data=[];for(const id of ['before','after']){const s=$(id).value;if(new TextEncoder().encode(s).length>500000)throw Error(id+': maximum input size is 500KB.');try{data.push(JSON.parse(s));}catch(e){throw Error(id+': invalid JSON. Check syntax; old results have been cleared.');}}result=ShapeDiff.compare(data[0],data[1],$('values').checked);$('summary').textContent=result.changes.length+(result.truncated?'+':'')+' changes'+(result.truncated?' - truncated at limit':'');$('status').className='small';$('status').textContent=result.truncated?'More changes exist. This is a partial report, not a complete comparison.':'Comparison complete. Exact parsed JSON differences only.';$('download').disabled=false;render();}catch(e){$('status').className='small error';$('status').textContent=e.message;$('summary').textContent='Comparison unavailable';}};
['before','after','values'].forEach(id=>$(id).addEventListener('input',invalidate));['filter','search'].forEach(id=>$(id).addEventListener('input',render));$('sample').onclick=loadSample;$('clear').onclick=()=>{$('before').value='';$('after').value='';invalidate();$('status').textContent='Inputs and results cleared.';};
for(const id of ['before','after'])$(id+'-file').onchange=async e=>{const f=e.target.files[0];if(!f)return;invalidate();try{if(f.size>500000)throw Error('Maximum file size is 500KB.');$(id).value=await f.text();$('status').textContent='Opened locally: '+f.name;}catch(err){$('status').textContent=err.message;}finally{e.target.value='';}};
$('download').onclick=()=>{if(!result)return;const u=URL.createObjectURL(new Blob([JSON.stringify(result,null,2)],{type:'application/json'}));const a=document.createElement('a');a.href=u;a.download='json-shape-diff.json';a.click();setTimeout(()=>URL.revokeObjectURL(u),1000);};loadSample();$('compare').click();
</script></body></html>
|