| Server IP : 139.59.63.204 / Your IP : 216.73.217.62 Web Server : Apache/2.4.58 (Ubuntu) System : Linux ubuntu-s-1vcpu-1gb-blr1-01 6.8.0-110-generic #110-Ubuntu SMP PREEMPT_DYNAMIC Thu Mar 19 15:09:20 UTC 2026 x86_64 User : root ( 0) PHP Version : 8.3.6 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : OFF Directory : /var/www/efbtechnology.com/lab/ |
Upload File : |
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Collapsible JSON Viewer</title>
<style>
body { font-family: monospace; padding: 20px; background: #f9f9f9; }
textarea { width: 100%; height: 150px; }
.json-viewer { background: #fff; border: 1px solid #ccc; padding: 10px; margin-top: 20px; min-height:125px; }
.toggle { cursor: pointer; user-select: none; margin-right: 5px; font-weight: bold; }
.key { color: brown; }
.string { color: green; }
.number { color: blue; }
.boolean { color: darkorange; }
.null { color: magenta; }
.children { padding-left: 20px; }
.collapsed > .children { display: none; }
</style>
</head>
<body>
<div style="width:100%;"><div style="float:left;width:40%;">
<h2>Paste JSON:</h2>
<textarea id="jsonInput" placeholder="Paste your JSON here"></textarea><br><br>
<button onclick="renderJSON()">Render JSON</button>
</div><div style="float:left;width:59%; margin-left:1%;">
<h2>Response:</h2>
<div id="jsonOutput" class="json-viewer"></div>
</div>
<script>
function renderJSON() {
const input = document.getElementById("jsonInput").value;
const output = document.getElementById("jsonOutput");
output.innerHTML = '';
try {
const json = JSON.parse(input);
const tree = createTree(json);
output.appendChild(tree);
} catch (e) {
output.textContent = "❌ Invalid JSON: " + e.message;
}
}
function createTree(data, key = '') {
const item = document.createElement('div');
const type = typeof data;
if (data && type === 'object') {
const isArray = Array.isArray(data);
const wrapper = document.createElement('div');
wrapper.className = 'children';
const toggle = document.createElement('span');
toggle.className = 'toggle';
toggle.textContent = '▼';
toggle.onclick = () => {
wrapper.style.display = wrapper.style.display === 'none' ? 'block' : 'none';
toggle.textContent = wrapper.style.display === 'none' ? '▶' : '▼';
};
const label = document.createElement('span');
label.innerHTML = key
? `<span class="key">"${key}"</span>: ${isArray ? '[' : '{'}`
: (isArray ? '[' : '{');
item.appendChild(toggle);
item.appendChild(label);
item.appendChild(wrapper);
for (let childKey in data) {
const child = createTree(data[childKey], childKey);
wrapper.appendChild(child);
}
const closing = document.createElement('div');
closing.textContent = isArray ? ']' : '}';
closing.style.marginLeft = '20px';
item.appendChild(closing);
} else {
// Leaf node (primitive value)
item.innerHTML = key
? `<span class="key">"${key}"</span>: ${syntaxColor(data)}`
: syntaxColor(data);
}
return item;
}
function syntaxColor(value) {
const type = typeof value;
if (type === 'string') return `<span class="string">"${value}"</span>`;
if (type === 'number') return `<span class="number">${value}</span>`;
if (type === 'boolean') return `<span class="boolean">${value}</span>`;
if (value === null) return `<span class="null">null</span>`;
return value;
}
</script>
</body>
</html>