Created base of json formatter and validator.

This commit is contained in:
2023-02-23 17:49:26 +01:00
parent 3c927f91cf
commit 735f600c66
5 changed files with 114 additions and 1 deletions

View File

@@ -0,0 +1,29 @@
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)
}
}

View File

@@ -43,6 +43,10 @@ function setDefaultContent(element, text) {
element.style.color = color_grey;
element.value = text;
}
if (id == "jsonArea") {
element.style.color = color_grey;
element.value = text;
}
}
}