T
Typebot3mo ago
nefer_l

Understanding Object Parsing in Typebot

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.
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
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!
No description
4 Replies
Hall
Hall3mo ago
Someone will reply to you shortly. In the meantime, this might help: -# This post was marked as solved by Baptiste. View answer.
Anthony
Anthony3mo ago
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?
nefer_l
nefer_lOP3mo ago
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.
nefer_l
nefer_lOP3mo ago
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[]).
No description

Did you find this page helpful?