// Attempt to pretty-print JSON if valid function prettyPrintJson() const raw = inputEditor.value; try const parsed = JSON.parse(raw); const pretty = JSON.stringify(parsed, null, 2); inputEditor.value = pretty; fileStatusSpan.innerText = '✅ Formatted JSON'; applyChanges(); // auto sync after formatting catch (e) alert('Not valid JSON. Could not prettify.\nError: ' + e.message); fileStatusSpan.innerText = '⚠️ Invalid JSON';
<script> (function() // DOM elements const inputEditor = document.getElementById('inputEditor'); const outputEditor = document.getElementById('outputEditor'); const applyBtn = document.getElementById('applyChangesBtn'); const downloadBtn = document.getElementById('downloadBtn'); const clearBtn = document.getElementById('clearBtn'); const formatJsonBtn = document.getElementById('formatJsonBtn'); const copyOutputBtn = document.getElementById('copyOutputBtn'); const fileLoader = document.getElementById('fileLoader'); const fileStatusSpan = document.getElementById('fileStatus'); save editor online
// Load from file: reads as text, fills inputEditor, then auto applyChanges to output. function loadFromFile(file) if (!file) return; const reader = new FileReader(); reader.onload = function(e) const content = e.target.result; inputEditor.value = content; applyChanges(); // automatically sync to output fileStatusSpan.innerText = `📄 Loaded: $file.name`; ; reader.onerror = function() alert('Error reading file.'); fileStatusSpan.innerText = '❌ Load error'; ; reader.readAsText(file, 'UTF-8'); // Attempt to pretty-print JSON if valid function
.button-group display: flex; flex-wrap: wrap; gap: 0.75rem; margin-top: 1rem; margin-bottom: 1rem; try const parsed = JSON.parse(raw)