29 lines
848 B
JavaScript
29 lines
848 B
JavaScript
function formatAndValidateJson(errorElement) {
|
|
const input = document.querySelector('#jsonBlock');
|
|
const errorOutput = document.getElementById(errorElement);
|
|
|
|
try {
|
|
const obj = JSON.parse(input.textContent);
|
|
input.innerHTML = JSON.stringify(obj, null, 2);
|
|
errorOutput.innerText = "";
|
|
hljs.highlightElement(input);
|
|
} catch (error) {
|
|
errorOutput.innerText = error;
|
|
console.error("Error: ", error)
|
|
}
|
|
}
|
|
|
|
function minimizeJson(errorElement) {
|
|
const input = document.querySelector('#jsonBlock');
|
|
const errorOutput = document.getElementById(errorElement);
|
|
|
|
try {
|
|
const obj = JSON.parse(input.textContent);
|
|
input.innerHTML = JSON.stringify(obj);
|
|
errorOutput.innerText = "";
|
|
hljs.highlightElement(input);
|
|
} catch (error) {
|
|
errorOutput.innerText = error;
|
|
console.error("Error: ", error)
|
|
}
|
|
} |