# Can't serialize HTMLScriptElement

**URL:** <https://forum.djangoproject.com/t/cant-serialize-htmlscriptelement/44506>\
**Category:** Mystery Errors\
**Created:** [March 14, 2026, 4:50am UTC](https://forum.djangoproject.com/t/cant-serialize-htmlscriptelement/44506 "2026-03-14T04:50:58Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![hess8](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/hess8/32/28833_2.png) [@hess8](https://forum.djangoproject.com/u/hess8)\
**Post date:** [March 14, 2026, 4:50am UTC](https://forum.djangoproject.com/t/cant-serialize-htmlscriptelement/44506/1 "2026-03-14T04:50:58Z")

</div>

I get this error when trying to pass a geojson object from the view context to a map:

`django can’t serialize object of unregistered class HTMLScriptElement`

in my template I have:

```auto
{{top7d_starts|json_script:"top7d_starts"}}

```

and in my map.js:

```auto
var top7d_starts = document.getElementById('top7d_starts');

```

The error occurs on this code for mapLibre:

```auto
map.on('load', () => {
    map.addSource('starts', {
        type: 'geojson',
        data: top7d_starts
    });
});

```

The geojson object is already serialized.

What steps am I missing? Or is there a better way to bring a geojson object from the view context to the js map?

---

<div class="post-metadata">

**Author:** ![matthiask](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/matthiask/32/115_2.png) [@matthiask](https://forum.djangoproject.com/u/matthiask)\
**Post date:** [March 14, 2026, 9:15am UTC](https://forum.djangoproject.com/t/cant-serialize-htmlscriptelement/44506/2 "2026-03-14T09:15:02Z")

</div>

You probably have to do something like:

```
const data = JSON.parse(top7d_starts.textContent)

```

And then pass the data variable, not the script element.

---

<div class="post-metadata">

**Author:** ![KenWhitesell](https://sea2.discourse-cdn.com/flex026/user_avatar/forum.djangoproject.com/kenwhitesell/32/280_2.png) [@KenWhitesell](https://forum.djangoproject.com/u/KenWhitesell)\
**Post date:** [March 14, 2026, 11:41am UTC](https://forum.djangoproject.com/t/cant-serialize-htmlscriptelement/44506/3 "2026-03-14T11:41:33Z")

</div>

> [@hess8](#):
>
> `django can’t serialize object of unregistered class HTMLScriptElement`
> 
> in my template I have:
> 
> ```auto
> {{top7d_starts|json_script:"top7d_starts"}}
> 
> ```

If you’re getting this error on the server, I’d look at what `top7d_starts` contains.

And if you are getting this error on the server, we’d need to see the view and template to help you diagnose this.
