HTML to JSON Converter Online — Free & Private

Paste HTML and get its element tree as JSON, with attributes as @ keys and text as #text. The conversion runs in your browser and nothing is uploaded.

Loading…
HTML → JSON for pages, tables and lists
Parses HTML in the browser and writes the element tree as JSON: one key per tag, attributes as @ keys, text as #text. Nothing is uploaded.

Developer notes

The HTML is parsed with DOMParser (text/html), then each element becomes an object keyed by its lowercased tag name. Attributes become keys prefixed with @ (@id, @class, @data-sku). An element with only text becomes a plain string, an empty element becomes {}. Sibling tags with the same name are grouped into an array, in document order. Inline tags are split from the text around them. In the first example, the paragraph with Tier: and a bold gold gives "strong": "gold" and "#text": "Tier:", and the position of the text is lost. All values are strings: 25 stays "25". Comments and the head are dropped, except the page title when the body has several top-level nodes. The browser repairs the markup first, so a table gains a tbody element.

Use cases

Pull the rows of an HTML table or the items of a list into JSON for a script. Turn a block of scraped markup into a fixture for an API test. See how a page is nested before you write CSS selectors or a parser.

About these options

For CSV output, choose the delimiter, how fields are quoted, the line endings and whether to write a header row. Auto uses a comma in English and a semicolon in French, German and Spanish, as Excel expects. For CSV input, the delimiter is detected on the first line (comma, semicolon, tab or pipe). You choose whether that line holds the column names. JSON output can use 2 or 4 spaces or a single line, with an optional recursive key sort. XML output can be pretty-printed with a chosen indent width. YAML output takes an indent width and a quoting mode for strings. XML comments are dropped, because the conversion goes through a JSON tree.

Examples

Full page with a header and a section

Input

<!DOCTYPE html> <html lang="en"> <body> <header><h1>Checkout API</h1></header> <main> <section id="pricing"> <p>Tier: <strong>gold</strong></p> <p>Seats: 25</p> </section> </main> </body> </html>

Output

{ "body": [ { "header": { "h1": "Checkout API" } }, { "main": { "section": { "@id": "pricing", "p": [ { "strong": "gold", "#text": "Tier:" }, "Seats: 25" ] } } } ] }

Table with a header row

Input

<table id="prices"> <tr><th>Plan</th><th>Seats</th></tr> <tr><td>Starter</td><td>5</td></tr> <tr><td>Team</td><td>25</td></tr> </table>

Output

{ "table": { "@id": "prices", "tbody": { "tr": [ { "th": [ "Plan", "Seats" ] }, { "td": [ "Starter", "5" ] }, { "td": [ "Team", "25" ] } ] } } }

Related tools

Other converters that start from HTML are linked on this page.

HTML → JSON FAQ

Parsing and limits

Is my HTML uploaded to a server?

No. The conversion uses the browser DOMParser in this tab, and FastMinify does not receive the markup.

What does the JSON look like?

Each element becomes an object named after its tag. Attributes are @ keys, text is #text, and repeated tags become arrays. A single element at the top becomes the root; several top-level nodes go under body.

Can I download the result?

Yes. Use Download after a successful conversion, or copy the output.

Why is the text next to a bold tag in a separate key?

An element that mixes text and child tags keeps the tags as keys and joins its own text into #text. In the first example, the paragraph with Tier: and a bold gold gives "strong": "gold" and "#text": "Tier:", so the original word order is not kept.

Are numbers and booleans converted?

No. HTML text has no types, so every value is a string: a cell with 25 gives "25". Convert the values in your own code if you need numbers.

Convert HTML to JSON, XML, YAML and Markdown.