> ## Documentation Index
> Fetch the complete documentation index at: https://docs.bringits.com/llms.txt
> Use this file to discover all available pages before exploring further.

# HTML Parse

> Parse an HTML string into a JSON DOM tree

The HTML Parse command (Command ID: **1024**, type **PARSE**) converts an HTML string on the step pipeline `data` field into a JSON tree shaped like `{ tag, attributes, children }`. Use it after HTTP or browser steps that produce HTML, then chain **JSONata (1022)** to extract the fields you need.

## Overview

The HTML Parse command provides functionality for:

* Turning raw HTML strings into a stable JSON DOM representation
* Preserving element tags, attributes, and nested structure
* Representing text nodes as `{ tag: "#text", text: "..." }`
* Handling single-root HTML, multiple roots, and mixed text + elements

## Command Type

**Command ID:** 1024\
**Command type:** PARSE

## Parameters

This command has **no configurable parameters**. The previous step must leave **`data` as a string** containing HTML (for example an HTTP response body or browser `outerHTML`).

| Parameter | Type | Description | Required |
| - | - | - | - |
| — | — | No params; input is the string on `data` | — |

## Input and output

**Input:** `data` must be a string. If `data` is already an object or array, the command fails.

**Output:** `data` is replaced by the DOM tree (unless a downstream command uses a different output key).

**Root shaping:**

| Input shape | Output root |
| - | - |
| Single element (e.g. `<ul>...</ul>`) | That element directly (`tag: "ul"`, …) |
| Multiple elements (`<p>one</p><p>two</p>`) | `{ tag: "#document-fragment", children: [...] }` |
| Text + elements (`intro <p>one</p> outro`) | `#document-fragment` with `#text` and element children in order |
| Plain text only | `{ tag: "#text", text: "..." }` |

**Example tree** (simplified):

```json theme={null}
{
  "tag": "ul",
  "attributes": { "class": "bets__option-list jbet" },
  "children": [
    {
      "tag": "li",
      "attributes": { "class": "jo betbox", "data-i": "4892446243" },
      "children": [
        {
          "tag": "span",
          "attributes": { "class": "jpr betbox__odd" },
          "children": [{ "tag": "#text", "text": "1,12" }]
        }
      ]
    }
  ]
}
```

## Usage Examples

### Parse HTML from the previous step

Add **HTML Parse (1024)** with empty params after a step that sets `data` to an HTML string:

```json theme={null}
{
  "id": 1024,
  "type": "PARSE",
  "params": {}
}
```

### Chain with JSONata to extract a value

After HTML Parse, add **JSONata (1022)**. Expressions use `data` as the tree root:

```json theme={null}
{
  "id": 1022,
  "type": "PARSE",
  "params": {
    "expression": "data.children[tag='li'].children[tag='span' and attributes.class ~> /jpr/].children[tag='#text'].text",
    "timeout": 5000
  }
}
```

### Collect all text nodes

```json theme={null}
{
  "id": 1022,
  "type": "PARSE",
  "params": {
    "expression": "data.**[tag='#text'].text",
    "timeout": 5000
  }
}
```

## Common Use Cases

* **Sportsbook / market HTML**: Parse list markup from a fetch or browser step, then JSONata into a flat list of odds or selections
* **Legacy HTML pages**: Avoid fragile regex on raw HTML; query the tree with JSONata
* **Browser scraping**: Parse `outerHTML` or a fragment returned from Run Custom Code

## Related Commands

* [XML Parse](https://docs.bringits.com/stream/commands/parse/xml-parse.md) - Parse XML strings into JSON (command ID 1019)
* [JSONata](https://docs.bringits.com/stream/commands/parse/jsonata.md) - Shape or extract fields from the DOM tree (command ID 1022)
* [Json Path](https://docs.bringits.com/stream/commands/parse/json-path.md) - JSONPath on JSON produced by earlier parse steps


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.