HTML vs. Vanilla JS vs. json-to-tag: What's the Difference?
Compare how the exact same UI component is created across the three Web Platform approaches — and why declarative JSON specifications offer the ideal balance of portability, safety, and simplicity.
Normal HTML
Writing direct HTML tags in files or template strings. The browser's C++ parser converts tags into DOM objects.
<label>Name</label>
<p>Test Content</p>
</div>
innerHTML, exposing apps to script injection.
Vanilla JavaScript
Manually instantiating DOM nodes via document.createElement() and assembling hierarchy
node-by-node.
wrap.id = "test-content";
const lbl = document.createElement("label");
lbl.textContent = "Name";
const p = document.createElement("p");
p.textContent = "Test Content";
wrap.append(lbl, p);
json-to-tag Specification
Pure JSON tree specification that buildSpecElement(spec) compiles directly into native DOM in
a single call.
tagName: "div",
attributes: { id: "test-content" },
children: [
{ tagName: "label", textContent: "Name" },
{ tagName: "p", textContent: "Test Content" }
]
};
const el = buildSpecElement(spec);
| Feature / Metric | Normal HTML | Vanilla JavaScript | json-to-tag (The Simple Way) |
|---|---|---|---|
| Data Format | Static HTML markup string | Imperative JS statements | Pure JSON Tree Object |
| API & DB Portability | Fragile string concatenation | Cannot serialize executable code | 100% JSON REST / DB Ready |
| XSS Injection Safety | High risk when using
innerHTML
|
Safe (property assignment) | Safe (Native node creation) |
| Code Verbosity & Effort | Low (templates only) | 5x-10x boilerplate lines | Minimal declarative schema |
| Schema & Capability Checks | Browser silently ignores errors | No schema validation ahead of time | tags.json Single Source of Truth |
| Runtime Dependencies | Zero dependencies | Zero dependencies | Zero dependencies (Native DOM) |
Integrate with 2 Lines of JavaScript
Works seamlessly in modern ES Module environments, Bundlers (Vite, Webpack, Rollup), and directly inside
browser script tags via automatic window.ks.jsonToTag registration.
import { buildSpecElement } from "@keshavsoft/json-to-tag";
// 2. Compile directly (v9 engine):
const domElement = buildSpecElement(mySpec);
document.getElementById("container").appendChild(domElement);
// 3. Browser Global (CDN auto-registered):
const node = window.ks.jsonToTag.buildSpecElement(mySpec);