# JSON parsing from text properties

**URL:** <https://community.hubspot.com/t/json-parsing-from-text-properties/121875>\
**Category:** CMS Development\
**Tags:** css\
**Created:** [December 4, 2024, 2:13pm UTC](https://community.hubspot.com/t/json-parsing-from-text-properties/121875 "2024-12-04T14:13:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![05311](https://avatars.discourse-cdn.com/v4/letter/0/c77e96/32.png) [@05311](https://community.hubspot.com/u/05311)\
**Post date:** [December 4, 2024, 2:13pm UTC](https://community.hubspot.com/t/json-parsing-from-text-properties/121875/1 "2024-12-04T14:13:19Z")

</div>

Hi everyone!

In my template (quotes) I want to add a custom section with a table of “included objects” (thery are not product/prices, but let’s say a description of what has been considered in the quote).  
It’s a 4 column table with a variable number of rows.  
My approach is: store JSON as string in a deal property, pull it and parse HubL and let it populate the table.  
I am having issues with the from\_json filter for parsing it, it seems not to work even on the simplest debugging test.  
I tried this code:

{% from ‘../../imports/mock\_data.html’ import SAMPLE\_TEMPLATE\_DATA as mock\_data %}  
{% set QUOTE = template\_data.quote || mock\_data.quote %}

\<section\>  
\<h3\>Debug Raw lista\_oggetti\</h3\>  
\<!-- Display lista\_oggetti as raw text --\>  
\<pre\>{{ QUOTE.associated\_objects.deal.lista\_oggetti }}\</pre\>  
\</section\>

\<section\>  
\<h3\>JSON Parsing Step-by-Step Debug\</h3\>  
\<!-- Step 1: Fetch the raw string --\>  
{% set lista\_oggetti = QUOTE.associated\_objects.deal.lista\_oggetti %}  
\<h4\>Raw String\</h4\>  
\<pre\>{{ lista\_oggetti|default(“No lista\_oggetti found”) }}\</pre\>

\<!-- Step 2: Try to parse the string --\>  
{% set lista\_oggetti\_parsed = lista\_oggetti|default(‘[]’)|from\_json %}  
\<h4\>Parsed JSON (from\_json)\</h4\>  
\<pre\>{{ lista\_oggetti\_parsed|default(“Parsing failed or no objects found”) }}\</pre\>

\<!-- Step 3: Check the parsed JSON structure --\>  
{% for item in lista\_oggetti\_parsed %}  
\<h4\>Parsed Object:\</h4\>  
\<pre\>{{ item|tojson }}\</pre\>  
{% else %}  
\<p\>No objects found in parsed JSON.\</p\>  
{% endfor %}  
\</section\>

\<section\>  
\<h3\>Fixing JSON Parsing\</h3\>  
\<!-- Step 1: Display raw string --\>  
{% set raw\_json = QUOTE.associated\_objects.deal.lista\_oggetti %}  
\<h4\>Raw JSON String:\</h4\>  
\<pre\>{{ raw\_json|default(“No lista\_oggetti found”) }}\</pre\>

\<!-- Step 2: Remove escaped characters --\>  
{% set clean\_json = raw\_json|replace(‘\\"’, ‘"’)|replace(‘\\n’, ‘’) %}  
\<h4\>Cleaned JSON String:\</h4\>  
\<pre\>{{ clean\_json }}\</pre\>

\<!-- Step 3: Parse cleaned JSON --\>  
{% set parsed\_json = clean\_json|from\_json %}  
\<h4\>Parsed JSON:\</h4\>  
\<pre\>{{ parsed\_json|default(“Parsing failed or no objects found”) }}\</pre\>

\<!-- Step 4: Debug parsed JSON structure --\>  
{% for item in parsed\_json %}  
\<h4\>Parsed Object:\</h4\>  
\<pre\>{{ item|tojson }}\</pre\>  
{% else %}  
\<p\>No objects found in parsed JSON.\</p\>  
{% endfor %}  
\</section\>

\<section\>  
\<h3\>Hardcoded JSON Parsing Test\</h3\>  
{% set test\_json = ‘[{“Oggetto”: “Test1”, “Stanza”: “Room1”, “Quantità”: 1, “IC”: “✓”, “Note”: “Note1”}, {“Oggetto”: “Test2”, “Stanza”: “Room2”, “Quantità”: 2, “IC”: “✗”, “Note”: “Note2”}]’ %}  
\<h4\>Hardcoded JSON String:\</h4\>  
\<pre\>{{ test\_json }}\</pre\>  
{% set parsed\_hardcoded\_json = test\_json|from\_json %}  
\<h4\>Parsed Hardcoded JSON:\</h4\>  
\<pre\>{{ parsed\_hardcoded\_json|default(“Hardcoded Parsing Failed”) }}\</pre\>  
\</section\>

\<section\>  
\<h3\>Simple Parsing Test\</h3\>  
{% set simple\_json = ‘{“key”: “value”}’ %}  
\<h4\>Raw JSON String:\</h4\>  
\<pre\>{{ simple\_json }}\</pre\>  
{% set parsed\_simple\_json = simple\_json|from\_json %}  
\<h4\>Parsed Output:\</h4\>  
\<pre\>{{ parsed\_simple\_json|default(“Simple Parsing Failed”) }}\</pre\>  
\</section\>

Basically everything works well until I try to parse with from\_json. Json string are valid json verified many times.  
Ideas?

---

<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:** [December 4, 2024, 11:58pm UTC](https://community.hubspot.com/t/json-parsing-from-text-properties/121875/2 "2024-12-04T23:58:05Z")

</div>

Hi, @05311 👋 Thanks for including your details and where you are getting stuck. I’d like to ask some of our community members if they have any relevant experience with similar issues — hey @AnzeKoprivec @Anton @jonchim, can you lend a hand here?

Thank you very much for taking a look! — Jaycee

---

<div class="post-metadata">

**Author:** ![AnzeKoprivec](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/anzekoprivec/32/228791_2.png) [@AnzeKoprivec](https://community.hubspot.com/u/AnzeKoprivec)\
**Post date:** [December 8, 2024, 6:54am UTC](https://community.hubspot.com/t/json-parsing-from-text-properties/121875/3 "2024-12-08T06:54:41Z")

</div>

Storing code in properties definetly works but I’ve had success with this only with Javascript/React code, HubL not so far, specially because I don’t think we have any methods for stringifying and parsing it with HubL and doing this with javascript isn’t possible since HubL is a server side templating language.  
I think there are better ways to solve your problem, why not just use a custom module? You can store the dynamic variables as deal properties and then just take those values in the module.  
Storing HubL on a property should be possible, the only concern is rednering it out. I would try this filter if anything but I still believe the appraoch is wrong and there are better ways to do what you’re looking for.  
Escape JSON would be for getting out of JSON.stringify

`{{ escape_string|escapejson }}`

But if you will just wrap your HTML + HubL with a single string then you should be able to just render this directly with

`{{ property }}`

otherwise using something like the |replace filter might be worth a try.
