# generate_mind_map() JSON Export vs. Web UI Visualization in notebooklm-py

> Explore the `generate_mind_map()` JSON export and Web UI visualization in notebooklm-py. Understand how JSON data translates to interactive diagrams for your projects.

- Repository: [Teng Lin/notebooklm-py](https://github.com/teng-lin/notebooklm-py)
- Tags: deep-dive
- Published: 2026-03-09

---

**The `generate_mind_map()` method produces raw JSON data for programmatic consumption, while the Notebook LM web UI renders that same JSON as an interactive visual diagram.**

The `notebooklm-py` library provides programmatic access to Notebook LM's mind map generation capabilities. Understanding the distinction between the `generate_mind_map()` JSON export and the web interface visualization is essential for building automated workflows. While both access the same underlying data, they serve fundamentally different purposes—machine-readable output versus human-friendly exploration.

## How generate_mind_map() Produces the JSON Export

The `generate_mind_map()` function in [`src/notebooklm/_artifacts.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/_artifacts.py) executes a three-step pipeline to create the exportable data.

### Step 1: RPC Invocation

First, the method calls `RPCMethod.GENERATE_MIND_MAP` with optional source IDs to request mind map generation from the server. This happens in lines 913-937 of [`src/notebooklm/_artifacts.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/_artifacts.py).

### Step 2: JSON Parsing and Note Persistence

The server returns a nested list containing the JSON string. The code extracts the payload from `result[0][0]`, parses it into a Python dictionary, and **creates a new note** with the raw JSON as its content (lines 76-84). The function returns `{"mind_map": <parsed-data>, "note_id": <id>}`.

### Step 3: Optional File Export

To write the data to disk, the separate `download_mind_map()` method (lines 943-951) retrieves the stored note and writes the JSON to a local file such as [`mindmap.json`](https://github.com/teng-lin/notebooklm-py/blob/main/mindmap.json).

## How the Web UI Handles Visualization

The browser interface does not read from exported files. Instead, it loads the note containing the JSON via the `GET_NOTES_AND_MIND_MAPS` RPC call. The UI identifies mind-map notes by checking for the presence of `children` or `nodes` keys in the content. It then feeds this JSON into a client-side renderer—implemented using D3 or VisJS-style libraries—to produce the interactive graph.

## Critical Differences Between Export and Visualization

| Aspect | generate_mind_map() JSON Export | Web UI Visualization |
|--------|----------------------------------|----------------------|
| **Data Source** | Raw RPC response stored as a note, optionally written to disk via `download_mind_map()` | Same JSON retrieved from the note via `GET_NOTES_AND_MIND_MAPS` |
| **Format** | Plain text JSON (machine-readable) | Interactive HTML/JavaScript diagram |
| **Purpose** | Downstream processing, archiving, third-party integrations | Human exploration and navigation |
| **Location** | Python dictionary, local `.json` file, or API response | Browser state within the Notebook LM application |

## Working with the JSON Export: Code Examples

### Generating Mind Maps via Python API

```python
from notebooklm import NotebookLMClient

async def demo():
    async with NotebookLMClient.from_storage() as client:
        # Generate the map for a notebook (all sources)

        result = await client.artifacts.generate_mind_map("nb_123")
        # result == {"mind_map": {...}, "note_id": "note_456"}

        print("Root node:", result["mind_map"]["name"])
        print("Saved as note:", result["note_id"])

```

This corresponds to the implementation in [`src/notebooklm/_artifacts.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/_artifacts.py) (lines 913-882).

### Exporting to a Local JSON File

```python
from notebooklm import NotebookLMClient

async def export():
    async with NotebookLMClient.from_storage() as client:
        # First generate (creates the note)

        await client.artifacts.generate_mind_map("nb_123")
        # Then write the JSON to disk

        path = "/tmp/mindmap.json"
        await client.artifacts.download_mind_map("nb_123", path)
        print(f"Mind map saved to {path}")

```

The `download_mind_map()` implementation resides at lines 943-951 in [`src/notebooklm/_artifacts.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/_artifacts.py).

### Command Line Usage

```bash

# JSON output (machine-readable)

notebooklm generate mind-map -n nb_123 --json

# => {"mind_map":{...},"note_id":"note_789"}

# Interactive UI (opens in web UI after generation)

notebooklm generate mind-map -n nb_123

# Status prints to console; visualization appears in Notebook LM under Artifacts → Mind Maps

```

The CLI implementation is found in [`src/notebooklm/cli/generate.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/cli/generate.py) (lines 28-66).

## Summary

- **`generate_mind_map()`** returns raw JSON data through an RPC call and stores it as a note within the notebook.
- **`download_mind_map()`** optionally persists that JSON to a local file for external processing.
- The **web UI** retrieves the same note data but renders it as an interactive visual graph using client-side JavaScript libraries.
- The JSON export is designed for **programmatic consumption**, while the UI visualization targets **human exploration**.

## Frequently Asked Questions

### Does generate_mind_map() automatically save a JSON file to my computer?

No. The method only creates a note within your Notebook LM project containing the JSON data. To obtain a local file, you must explicitly call `download_mind_map()` or use the CLI with appropriate flags.

### Can I use the JSON export with third-party visualization tools?

Yes. The export uses a standard hierarchical structure with `nodes` and `children` keys, making it compatible with D3.js, Vis.js, or custom graph renderers. The format matches exactly what the official web UI consumes.

### Why does the web UI show a mind map immediately while the API returns JSON?

The web UI performs the rendering step automatically. When you generate a mind map through the browser, the application receives the same JSON payload but immediately passes it to a client-side visualization engine. The API separates these concerns, giving you raw data without presentation logic.

### Is the JSON structure stable for production integrations?

According to the current implementation in [`src/notebooklm/_artifacts.py`](https://github.com/teng-lin/notebooklm-py/blob/main/src/notebooklm/_artifacts.py), the structure relies on standard keys like `children` and `nodes` to identify mind-map data. This matches the detection logic used by the web UI's `GET_NOTES_AND_MIND_MAPS` handler, suggesting a stable contract for parsing.