I have a programmable email module that was working perfectly about 2 months ago, but now the “fromjson” usage fails validation with this error:
Invalid input for ‘fromjson’: input could not be converted to an object
I haven’t changed any code. Because of this I am unable to make changes because it won’t publish with validation errors.
What I’m doing: Using the fromjson filter to parse JSON data stored in a contact property for abandoned cart emails:
{% set cart_items_json = contact.cart_items %}
{% set cart_items = cart_items_json|fromjson %}
{% for item in cart_items %}
<!-- display cart item -->
{% endfor %}
The problem:
This worked fine 2 months ago
Now getting validation errors when trying to save/publish
The validator blocks fromjson even though it’s in a programmable email module
When I bypass validation (undo + quick publish), the emails actually render correctly
What I’ve tried:
Adding |safe filter
Conditional checks
Different syntax variations
All still trigger validation errors
Question: Did HubSpot change validation rules recently? Is there a new approved way to parse JSON contact properties in programmable emails? This is blocking critical abandoned cart functionality.
Hi @fordnichols, welcome to HubSpot’s Developer forums!
Right off the bat, I’m tagging in a couple of our top experts, @Teun-SB and @Anton-B, to see if they have encountered this specific validation shift recently or have other workarounds for the fromjson filter behavior.
I will note, that I am not a developer, but here is what I’m hearing back from my AI deep dives: The error “input could not be converted to an object” during validation often occurs because the validator interprets the contact.cart_items property as null or undefined, whereas at runtime (when sending a real email), it has a value.
To pass the validation check, you often need to provide a “fallback” string that is valid JSON so the filter has something to process even when the contact property is empty.
Could you try updating your code to include a default value before the filter?
{% set cart_items_json = contact.cart_items|default(‘[]’) %}
{% set cart_items = cart_items_json|fromjson %}
Or combined:
{% set cart_items = (contact.cart_items|default(‘[]’))|fromjson %}
If the above doesn’t clear the error, it is possible the validator is seeing the data as “unsafe” (HTML escaped). Ensure the safe filter is applied before fromjson.
{% set cart_items = (contact.cart_items|default(‘[]’)|safe)|fromjson %}
Again, please keep in mind that the above coding suggestions are AI generated.
This is a really frustrating situation especially when your code worked fine before and now suddenly the validator is blocking you. What you are experiencing is not a code problem on your end but a change in how HubSpot’s validation engine handles the fromjson filter during the save/publish stage.
The root issue is that during validation, the contact property contact.cart_items is being evaluated as null or undefined because there is no actual contact record loaded in that validation context. The fromjson filter cannot parse null or an empty string, so it throws the error even though your code would work perfectly fine when the email is actually sent to a real contact with cart data.
Here is what you need to do to fix this:
Add a default fallback value so the validator has valid JSON to work with during the validation pass. Change your code from this:
{% set cart_items_json = contact.cart_items %}
{% set cart_items = cart_items_json|fromjson %}
To this:
{% set cart_items = (contact.cart_items|default(‘[]’))|fromjson %}
This tells HubSpot to use an empty JSON array [] as the default value if contact.cart_items is null or missing. The validator will now have valid JSON to parse, so it will stop throwing the error. When the email goes out to real contacts who have cart_items populated, it will use the actual data instead of the default.
If you need to add the safe filter as well for any HTML content in your JSON, you can combine them like this:
{% set cart_items = (contact.cart_items|default(‘[]’)|safe)|fromjson %}
After you make this change, the validation should pass and you will be able to publish your email template without needing to bypass validation. Your emails will still render correctly with the actual cart data when they are sent.
The reason this started happening about 2 months ago is that HubSpot likely tightened their validation engine to catch more edge cases, but it ended up being overly strict for programmable modules where contact data is not available during the validation step. Adding the default filter is the standard workaround for this.
HubSpot changed validation so fromjson fails if the contact property is empty during validation. To fix it, use a default JSON value so the validator has something valid to parse, for example:
{% set cart_items = (contact.cart_items|default('[]'))|fromjson %}
This stops the validation error and still works when real cart data is present.
Thanks you all for the responses, however setting fallback defaults does not fix the error. It seems like it should but I tried every kind of syntax and no dice.
I finally managed to fix it through a bunch of trial and error by adding the following to my conditional:
{% if cart_items_json and “[” in cart_items_json and “{” in cart_items_json %}
It’s a bit hacky but the only thing I could get to work. Checking for the those beginning chars in the json string must be enough to bypass the null or undefined value of {{ contact.cart_items }} during validation.
So, for reference, my final code went from:
{% set cart_items_json = contact.cart_items %}
{% set cart_items = cart_items_json|fromjson %}
{% for item in cart_items %}
<!-- display cart item -->
{% endfor %}
to:
{% set cart_items_json = contact.cart_items %}
{% if cart_items_json and "[" in cart_items_json and "{" in cart_items_json %}
{% set cart_items = cart_items_json|fromjson %}
{% if cart_items and cart_items|length > 0 %}
{% for item in cart_items %}
<!-- display cart item -->
<!-- close conditionals -->