Share feedback, ideas and get community help

Updated 5 months ago

How to store complex JSON content in a variable

At a glance

The community member is asking for an example of how to store the result of an HTTP request in a variable. They explain that to store complex content like an object, they can use JSON.stringify to convert it to text, and then use JSON.parse to parse it back into an object when needed. The community member is having trouble storing the data from an API response in a variable, as the variable comes back as undefined.

In the comments, another community member suggests saving parts of the data in several variables, which they recommend using with Typebot.

There is no explicitly marked answer in the provided information.

Can someone please give an example of how to do this with the result of an http request?

"If you really need to save a complex content into a variable, for example an object, you can use the JSON.stringify function to convert it into a text. And whenever you are using the variable, you can dynamically parse it back into an object using JSON.parse in an inline format:"

For example, I'm calling a GET from an API, which returns a JSON block of data. I would like to store all of it in a variable, so I can work with it - probably through a script block - and pull out the data I want. I'm not sure how to store the data in the variable correctly. When I try to save some portion of the data to a variable, and then return the variable, it comes back as undefined.
B
1 comment
Why don’t you save part of it in several variables? This is what I recommend with typebot
Add a reply
Sign up and join the conversation on Discord