Files
release11-tools/Frontend/assets/scripts/tools/json.js
2023-02-28 14:08:26 +01:00

39 lines
1.4 KiB
JavaScript

function formatAndValidateJson(errorElement) {
const input = document.querySelector('#jsonBlock');
const processInfo = document.getElementById(errorElement);
try {
const start = new Date();
const obj = JSON.parse(input.textContent);
input.innerHTML = JSON.stringify(obj, null, 2);
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) {
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
console.error("Error: ", error)
}
}
function minimizeJson(errorElement) {
const input = document.querySelector('#jsonBlock');
const processInfo = document.getElementById(errorElement);
try {
const start = new Date();
const obj = JSON.parse(input.textContent);
input.innerHTML = JSON.stringify(obj);
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) {
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
console.error("Error: ", error)
}
}