Code Tools

HTML → JSON

All tools

Turn a block of HTML into a nested JSON structure of tags, attributes and children.

How it works

Four simple steps

1

Paste HTML

Add a fragment; minified markup gives the cleanest output.

2

Parsed by the browser

DOMParser builds the tree, fixing nesting the way browsers do.

3

Serialized to JSON

Each element becomes { tag, attrs, children } starting at body.

4

Save dom.json

Copy the JSON or download it for your tests.

HTML → JSON

About HTML → JSON

You are writing a test that asserts on rendered markup, or feeding a page fragment into a script that prefers data to strings. Converting the HTML to a JSON tree gives you something you can walk with plain object access.

The converter parses your markup with DOMParser and serializes the body element recursively. Every element becomes an object with three fields: tag (the lowercase tag name), attrs (attribute names mapped to values) and children (an array). Text nodes are included in children as plain strings in document order, so mixed content like <p>Hi <b>there</b></p> keeps its sequence. Comments are skipped. The JSON is indented with two spaces and downloads as dom.json.

Whitespace between tags counts as text, so indented source produces strings such as "\n " among the children. Minify the markup first, or filter out whitespace-only strings in your code. The top-level object is always the body element, and anything the parser places in head (title, meta, link) is not included. To read the result comfortably, open it in the collapsible JSON viewer. For a quick visual outline rather than data, use the DOM Visualizer, and to export only certain elements, filter them first with the Element Extractor.

The conversion runs on an inert document in your browser, with no scripts executed and no request sent.

Keyboard shortcut

Ctrl Enter - Run tool
FAQ

Frequently asked questions

See all FAQs

Answers for this tool. For site-wide help, open the FAQ hub.

Not with this tool. The structure is simple enough to rebuild with a short recursive function: write the tag and its attrs, then each child in order.

Yes. They appear in attrs with an empty string as the value, which is how the DOM reports them.

Serialization starts at body. Elements the parser assigns to head, including title, meta and link, sit outside that tree.

View more FAQs

Related tools

View all

HTML Formatter

Beautify and indent HTML markup.

Open

CSS Formatter

Format and pretty-print CSS.

Open

JS Formatter

Beautify JavaScript code.

Open

JSON Formatter

Beautify and validate JSON.

Open

Explore 321 free tools

Everything you need as a developer, marketer or creator - in one beautiful place.

Browse all tools