Share feedback, ideas and get community help

Updated 2 weeks ago

Understanding Object Parsing in Typebot

At a glance
A community member is having trouble handling parsed objects in Typebot. They can successfully parse a string into an object in their dev console, but when they try the same experiment in Typebot, the parsed variable is not recognized as an object. The community member asks if they need to parse the object every time they access it, or if there is a correct method to save it as an object. Another community member reproduces the issue and suggests that Typebot variables can only be text (string) or a list of texts (string[]). The answer is found in the Typebot documentation, which confirms this limitation.
Useful resources
Hey all,

I'm having some trouble with handling parsed objects in Typebot and could really use some help. Here's the issue I'm encountering:

I've got a simple experiment where I'm working with an object represented as a string. In my dev console, I can successfully parse the string into an object and test its type – the expected results are as follows:
  1. The string initially returns false for an 'is object' condition.
  2. After parsing it to an object, it returns true for the same condition.
Plain Text
var objectString = `{
  "before":[{"plumbers_id": "000", "result_id": "aaa"},{"plumbers_id": "111", "result_id": "bbb"},{"plumbers_id": "222", "result_id": "ccc"}],
  "during":[{"plumbers_id": "333", "result_id": "ddd"},{"plumbers_id": "444", "result_id": "eee"},{"plumbers_id": "555", "result_id": "fff"}],
  "after":[{"plumbers_id": "666", "result_id": "ggg"},{"plumbers_id": "777", "result_id": "hhh"},{"plumbers_id": "888", "result_id": "iii"}]
}`;
undefined

typeof objectString === 'object' && objectString !== null;
false

objectString = JSON.parse(objectString);
{before: Array(3), during: Array(3), after: Array(3)}

typeof objectString === 'object' && objectString !== null;
true


However, when I try the same experiment within Typebot, the results differ.

After parsing the string and even saving the parsed variable, the second condition test still returns false.

Here's a screencast detailing the steps and where things go wrong: https://www.youtube.com/watch?v=gD6HEFkJrmo

Can anyone provide insights into why the parsed variable isn't being recognized as an object in Typebot even though I'm explicitly saving it as a parsed value?

Do we have to parse it every time we access it, or is there a correct method to save it as an object?

Thanks in advance for any help or guidance!
Marked as solution
Found the answer: https://docs.typebot.io/editor/variables#valid-value-types

TL;DR: Variables content can either be a text (string) or a list of texts (string[]).
View full solution
A
n
3 comments
Heya nefer,
Hmm, after reproducing your case, I indeed run into the same issue, where the type of the object remains string, despite explicitly parsing it as JSON when overwriting the variable's value.

My first guess was that it was not properly taking into account the new value of the same variable, so I saved the parsed object in a new variable (named differently), but its typeof still returned string, so it doesn't come from that.

I even tried several things to explicitly turn it into an object (like the line below), but it STILL returns it as a string, which is odd.
Object.fromEntries(Object.entries(JSON.parse({{obj}})))

I'm guessing you're doing that in the first place because you'll receive the response from an API as a string and need to convert it to JSON within Typebot? Or is it for another use case?
Thanks for looking into this, @Anthony. It would be nice to save a JSON object as a Typebot variable instead of parsing it every time.

You're right. I'm doing a GET request from my database and need to parse a JSON object that's a string so I can execute an operation on it in Typebot and then do a PATCH request back to my database.
Found the answer: https://docs.typebot.io/editor/variables#valid-value-types

TL;DR: Variables content can either be a text (string) or a list of texts (string[]).
Add a reply
Sign up and join the conversation on Discord