# Dynamically-Generated JSON-LD for BreadcrumbList

**URL:** <https://community.hubspot.com/t/dynamically-generated-json-ld-for-breadcrumblist/119364>\
**Category:** CMS Development\
**Created:** [October 28, 2024, 8:44pm UTC](https://community.hubspot.com/t/dynamically-generated-json-ld-for-breadcrumblist/119364 "2024-10-28T20:44:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![DInc](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dinc/32/203091_2.png) [@DInc](https://community.hubspot.com/u/DInc)\
**Post date:** [October 28, 2024, 8:44pm UTC](https://community.hubspot.com/t/dynamically-generated-json-ld-for-breadcrumblist/119364/1 "2024-10-28T20:44:05Z")

</div>

Hi,

Wondering if anyone has a HubL snippet they use for dynamically generating JSON-LD for breadcrumbs. I originally thought `content.topic_list` would contain every segment in the blog post’s URL, but I was incorrect. Given the following URL:

[https://www.mysite.com/segment1/segment2/page-name](https://www.mysite.com/segment1/segment2/page-name)

How would go about dynamically generating a breadcrumb JSON as below?

```lia-code-sample
{
 "@type": "BreadcrumbList",
 "itemListElement": [
 {
 "@type": "ListItem",
 "position": 1,
 "name": "Home",
 "item": "https://www.mysite.com"
 },
 {
 "@type": "ListItem",
 "position": 2,
 "name": "Segment1",
 "item": "https://www.mysite.com/segment1"
 },
 {
 "@type": "ListItem",
 "position": 3,
 "name": "Segment2",
 "item": "https://www.mysite.com/segment1/segment2"
 },
 {
 "@type": "ListItem",
 "position": 4,
 "name": "Page Name",
 "item": "https://www.mysite.com/segment1/segment2/page-name"
 }
 ]
 }

```

---

<div class="post-metadata">

**Author:** ![Jaycee\_Lewis](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/jaycee_lewis/32/61352_2.png) [@Jaycee\_Lewis](https://community.hubspot.com/u/Jaycee_Lewis)\
**Post date:** [October 29, 2024, 7:48pm UTC](https://community.hubspot.com/t/dynamically-generated-json-ld-for-breadcrumblist/119364/2 "2024-10-29T19:48:10Z")

</div>

Hi, @DInc 👋 Thanks for your question. I’d like to invite some of our community experts to the conversation — hey @albertsg @alyssamwilie @Anton @Teun do you have any experience creating this dynamically in the manner @DInc is describing?

I found this [**blog post**](https://developers.hubspot.com/blog/how-to-use-structured-data-schema-markup-in-hubspot-to-improve-seo) from @AJLaPorte that I’ll leave for other folks who may come across your post when searching.

Thank you very much for taking a look! — Jaycee

---

<div class="post-metadata">

**Author:** ![DInc](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dinc/32/203091_2.png) [@DInc](https://community.hubspot.com/u/DInc)\
**Post date:** [October 29, 2024, 7:57pm UTC](https://community.hubspot.com/t/dynamically-generated-json-ld-for-breadcrumblist/119364/3 "2024-10-29T19:57:26Z")

</div>

Thanks for your reply [@Jaycee\_Lewis](https://community.hubspot.com/t5/user/viewprofilepage/user-id/127074). After many attempts - and failures - in generating a dynamic list of absolute URLs from a URL with multiple segments, I decided to add a repeater Bradcrumbs schema field as a module and let the editor speficy them on their own. Though, if there was an object provided to keep track of the various ‘crumbs’ leading to every page/blog post, I imagine we could iterate through that to generate a viable BradcrumbList schema.

---

<div class="post-metadata">

**Author:** ![GiantFocal](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/giantfocal/32/41969_2.png) [@GiantFocal](https://community.hubspot.com/u/GiantFocal)\
**Post date:** [October 31, 2024, 8:03am UTC](https://community.hubspot.com/t/dynamically-generated-json-ld-for-breadcrumblist/119364/4 "2024-10-31T08:03:10Z")

</div>

Hi @DInc,

Assuming all the path URLs are pages, you can split the path and construct as list items:

For example:

```lia-code-sample
{% set url_segments = request.path.split('/') %}
{
 "@type": "BreadcrumbList",
 "itemListElement": [
 {% for segment, i in url_segments %}
 {
 "@type": "ListItem",
 "position": {{ i+1 }},
 "name": "{{ segment|capitalize }}",
 "item": "{{ request.base_path }}/{{ segment }}"
 }
 {% if not loop.last %},{% endif %}
 {% endfor %}
 ]
}

```

Let me know if you need to integrate the post’s topic into the breadcrumb.

---

<div class="post-metadata">

**Author:** ![DInc](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dinc/32/203091_2.png) [@DInc](https://community.hubspot.com/u/DInc)\
**Post date:** [October 31, 2024, 8:35pm UTC](https://community.hubspot.com/t/dynamically-generated-json-ld-for-breadcrumblist/119364/5 "2024-10-31T20:35:24Z")

</div>

This wouldn’t work because each segment’s absolute url would need to contain the previous segment as part of its url, if it exists. Using your example, I would end up with `[https://www.mysite.com/page-name](https://www.mysite.com/segment1/segment2/page-name%60)` as the last segment’s absolute URL, which would be incorrect.
