function formatAndValidateJson(errorElement) {
const input = document.querySelector('#jsonBlock');
const processInfo = document.getElementById(errorElement);
const start = new Date();
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting"
fetch(address, {
method: 'POST',
body: input.textContent
})
.then(async (response) => {
if (!response.ok) {
throw Error(await response.text());
}
return response.text();
})
.then((data) => {
input.innerText = data;
processInfo.innerText = "";
hljs.highlightElement(input);
const end = new Date();
processInfo.innerHTML = "Validation and formatting time: " + (end.getMilliseconds() - start.getMilliseconds()) + "ms";
})
.catch((error) => {
processInfo.innerHTML = "" + error + "";
console.error('Error:', error);
});
}
function minimizeJson(errorElement) {
const input = document.querySelector('#jsonBlock');
const processInfo = document.getElementById(errorElement);
const start = new Date();
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/minimize"
fetch(address, {
method: 'POST',
body: input.textContent
})
.then(async (response) => {
if (!response.ok) {
throw Error(await response.text());
}
return response.text();
})
.then((data) => {
input.innerText = data;
processInfo.innerText = "";
hljs.highlightElement(input);
const end = new Date();
processInfo.innerHTML = "Validation and formatting time: " + (end.getMilliseconds() - start.getMilliseconds()) + "ms";
})
.catch((error) => {
processInfo.innerHTML = "" + error + "";
console.error('Error:', error);
});
}