html_to_json

Convert an HTML fragment into a structured JSON tree.

Syntax

{{ value | html_to_json }}

Example

01

Basic usage

InputTS
1{2  "html": "<p>Hello</p>"3}
TemplateKNAP
1{{ html | html_to_json }}
OutputKNAP
1{"type":"element","tag":"p","children":[{"type":"text","content":"Hello"}]}

Behavior

  • Requires browser-compatible DOM globals and the knap/html preset.