APIs & Integrations

PhilippeStoltz
Member

HubL module : cannot convert a contact property to JSON

SOLVE

Hi all !

I have a contact property as a JSON string that is not recognized as JSON in HubL template named dispos :

valid json but too long

{"days":[{"col":0,"rows":[{"row":0,"cellPresent":true,"span":0}, .... {"row":22,"cellPresent":true,"span":0},{"row":23,"cellPresent":true,"span":0}]}]}

I cannot find a way for this json string to be converted to a JSON object in my module :

{% set calendar = contact.dispos |fromjson %}

{% set columnHeaders = ['Heures', 'Lundi', 'Mardi', 'Mercredi', 'Jeudi', 'Vendredi', 'Samedi', 'Dimanche'] %}

{% macro renderRow(rowIndex) %}
<tr>
<td>{{"%02d"|format(rowIndex)}}:00 - {{rowIndex==23 ? "00" : "%02d"|format(rowIndex + 1)}}:00</td>
{% for elem in calendar.days %}
{{renderCell(rowIndex, elem)}}
{% endfor %}
</tr>
{% endmacro %}

{% macro renderCell(rowIndex, elem) %}
{%set cellInfo = elem.rows[rowIndex] %}

{% if cellInfo.cellPresent %}
<td
{% if cellInfo.span > 0 %}
rowspan="{{ cellInfo.span }}" style="background-color:#1F8E92"
{% endif %}
></td>
{% endif %}
{% endmacro %}

{% set test = contact.dispos | json %}
<span>{{ test.days[0].col }}</span>
<table border="1">
<tr>
{% for header in columnHeaders %}
<th>{{ header }}</th>
{% endfor %}
</tr>
{% for x in range(0,24) %}
{{renderRow(x)}}
{% endfor %}
</table>

Any help is much appreciated !

Philippe

 

 

0 Upvotes
1 Accepted solution
WendyGoh
Solution
HubSpot Employee
HubSpot Employee

HubL module : cannot convert a contact property to JSON

SOLVE

Hey @PhilippeStoltz,

 

I have checked in with our team and currently filters on any personalization variables (such as but not limited to contacts, company, and deal variables) is not supported for email in HubSpot due to how emails are rendered. Filters can be applied to these properties on HubSpot CMS page and blog templates. (You can check out the yellow box alert that our team added on this documentation: HubL Supported Filters).

View solution in original post

0 Upvotes
4 Replies 4
WendyGoh
HubSpot Employee
HubSpot Employee

HubL module : cannot convert a contact property to JSON

SOLVE

Hey @PhilippeStoltz,

 

I'm also seeing the same behavior and it looks like if we use filters such as escapejson it works. In this case, I'll have to check in with our internal team and I'll keep you updated here!

0 Upvotes
PhilippeStoltz
Member

HubL module : cannot convert a contact property to JSON

SOLVE

Hi Wendy,

 

Thanks for the reply.
I tried using the escapejson filter but still does not work :

 

{% set calendar = contact.dispos | escapejson | fromjson %}

 

Philippe

WendyGoh
Solution
HubSpot Employee
HubSpot Employee

HubL module : cannot convert a contact property to JSON

SOLVE

Hey @PhilippeStoltz,

 

I have checked in with our team and currently filters on any personalization variables (such as but not limited to contacts, company, and deal variables) is not supported for email in HubSpot due to how emails are rendered. Filters can be applied to these properties on HubSpot CMS page and blog templates. (You can check out the yellow box alert that our team added on this documentation: HubL Supported Filters).

0 Upvotes
deiv
Participant

HubL module : cannot convert a contact property to JSON

SOLVE

Hi Wendy,

 

I'm having the same issue, one of my contact properties is a text that contains a JSON and I would like to parse it in a marketing email so I can print its content.

 

I guess that HubL is rendered in server-side, so why filters are not supported? Could you please check with the dev team if there is any workaround?

 

Thanks!