Local-First Engineering: Why In-Browser JSON and Recursive XML Formatting Matters
Protecting proprietary payloads and debugging production payloads with client-side execution, zero external telemetry, and deterministic formatting.
Explores the philosophy and mechanics behind PrettyPrint. Demonstrates why developers should avoid paste-into-cloud formatters for sensitive enterprise logs, and reveals the recursive AST algorithms used to parse and highlight malformed XML and JSON completely in-browser.
#The Security Risk of 'Paste-to-Format' Web Utilities
#Recursive Formatting Algorithm for Complex XML Trees
// Core recursive XML indentation logic in PrettyPrint
export function formatXml(xmlString, indentChar = ' ') {
let formatted = '';
let indent = 0;
// Clean whitespace between tag boundaries
const cleanXml = xmlString.replace(/>\s*</g, '><').trim();
const tokens = cleanXml.split(/(<[^>]+>)/g).filter(Boolean);
tokens.forEach((token) => {
if (token.startsWith('<?') || token.startsWith('<!')) {
formatted += indentChar.repeat(indent) + token + '\n';
} else if (token.startsWith('</')) {
indent = Math.max(0, indent - 1);
formatted += indentChar.repeat(indent) + token + '\n';
} else if (token.startsWith('<') && !token.endsWith('/>')) {
formatted += indentChar.repeat(indent) + token + '\n';
indent++;
} else {
// Content or self-closing tag
formatted += indentChar.repeat(indent) + token + '\n';
}
});
return formatted.trim();
}#Syntax Highlighting Without Heavy AST Engines
Rad Tome leads software architecture, systems engineering, and open-source tooling at RadTome. Specializes in GraalVM Ahead-of-Time compilation, distributed microservices, Chrome Manifest V3 APIs, and local-first browser developer utilities.
This publication is part of RadTome's open developer knowledge base. All technical materials are validated against active production systems, open-source repositories, and industry standard benchmarks.