Working json formatter with xml tags support.

This commit is contained in:
2023-03-01 16:02:38 +01:00
parent 4a19c45fa2
commit 753650f81c
6 changed files with 268 additions and 15 deletions

View File

@@ -1,21 +1,33 @@
function formatAndValidateJson(errorElement) {
const input = document.querySelector('#jsonBlock');
const processInfo = document.getElementById(errorElement);
const start = new Date();
try {
const start = new Date();
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting"
const obj = JSON.parse(input.textContent);
input.innerHTML = JSON.stringify(obj, null, 2);
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 = "<b style='color: black'>Validation and formatting time:</b> <span style='color: green'>" + (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
} catch (error) {
})
.catch((error) => {
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
console.error("Error: ", error)
}
console.error('Error:', error);
});
const end = new Date();
processInfo.innerHTML = "<b style='color: black'>Validation and formatting time:</b> <span style='color: green'>" + (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
}
function minimizeJson(errorElement) {
@@ -31,7 +43,8 @@ function minimizeJson(errorElement) {
hljs.highlightElement(input);
const end = new Date();
processInfo.innerHTML = "<b style='color: black'>Validation and formatting time:</b> <span style='color: green'>" + (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
processInfo.innerHTML = "<b style='color: black'>Validation and formatting time:</b> <span style='color: green'>"
+ (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
} catch (error) {
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
console.error("Error: ", error)