import { htmlSafe } from "@ember/template";
import { escapeExpression } from "discourse/lib/utilities";
export function jsonToHtml(json) {
if (json === null) {
return "null";
}
if (typeof json !== "object") {
return escapeExpression(json);
}
let html = "
";
for (let [key, value] of Object.entries(json)) {
html += "- ";
key = escapeExpression(key);
if (typeof value === "object" && Array.isArray(value)) {
html += `${key}: ${jsonToHtml(value)}`;
} else if (typeof value === "object") {
html += `${key}: `;
} else {
if (typeof value === "string") {
value = escapeExpression(value).replace(/\n/g, "
");
}
html += `${key}: ${value}`;
}
html += " ";
}
html += "
";
return htmlSafe(html);
}