HTML to JSON tree
Build JSON from the tokenizer node tree: elements become `{ tag, attrs, children }`, text becomes `{ text }`, comments and the doctype get their own nodes, with switches for attributes, comments and indentation. The output is structured, diff-able data rather than the raw string in one field.
Runs in your browserEvery computation happens in your browser — your data never leaves this device.
Result
The result can be copied directly.
Paste HTML to see the JSON tree
Characters: 0 · Lines: 0 · Elements: 0 · Text nodes: 0
What this tool does
- Turn HTML into diff-able JSON for version comparison.
- Prepare structured node data for tests or a crawler.
- Inspect how attributes, comments and text nodes are parsed.
Example
Input
<div id="a">Hi</div>
Output
[
{
"tag": "div",
"attrs": {
"id": "a"
},
"children": [
{
"text": "Hi"
}
]
}
]Elements become `{ tag, attrs, children }`, text becomes `{ text }`, and whitespace-only text nodes are dropped.
Frequently asked questions
Is the output a DOM object?
No. It is a plain JSON tree (`tag` / `attrs` / `children`) that can be serialized, compared and passed to other processes.
Where did whitespace text nodes go?
Text nodes that collapse to whitespace are dropped so the JSON is not full of no-op entries.
Are quoted attribute values handled?
Yes. Attributes are parsed by the tokenizer, so single, double and unquoted forms all work and boolean attributes become `true`.
Can it turn JSON back into HTML?
No. This export is one-way; use a formatter or serializer to go back.
Keywords:html2jsonJSON treedeveloper