Table of Contents

Formulas - Object

Dilyara Updated by Dilyara

If is your first time with Formulas, please check our Getting Started guide here and our crash course here

Formulas available

  • GetValue
  • ToJSON

GetValue

Get value from the key "Name"

Imagine that you have JSON like this one, stored in a variable type array called @response:

{
"Name":"Landbot",
"Web":"landbot.io"
}

And you want to capture "Landbot" that is located in key "Name", here is how you can capture that value

GetValue(@response,"Name")
Get value from the first item of the array that is in the key "colors"

Imagine that you want an item that is inside an array, let's say you have the JSON below stored in a variable type array called "@response" and you want to capture "red" , that is the first item of the array that is in the key "colors".

{
"materials":["iron"],
"colors":["red", "blue"]
}

Here is how you can do to capture "red":

GetValue(@response,"colors",0)

Get Value from a nested object

For nested objects, we will use nested nest formulas. So, let's say we have a JSON in a variable called @response with these values:

{
"name":"Landbot",
"details":{
"web":"landbot.io"
}
}

And we want the value "landbot.io" that is in the key "web", that is inside the key "details". Here is how we will do it:

GetValue(GetValue(@response,"details"),"web")

ToJSON

Transform string to a JSON

There might be a case that you need to build a JSON out of values collected in Landbot, with to JSON, you can build it directly as below:

ToJSON('{"city":"Valencia","country":"Spain"}')

Create a JSON Object using user inputs (value as variable)

In this case we want to create an object using the variables @name and @email

ToJSON('{"name":"@name","email":"@email"}')

Create a JSON Object using user inputs (key and value are variables)

Let's say we want to let the user select 2 inputs, a category (we will use "country"), that we will store in the variable @category and the country selected in the variable @country

Then the formula will be like this:

As you see below, key and value are variables:

ToJSON('{"@{category}":"@{country}"}')

How did we do?

Formulas - Date

Formulas - Logical

Contact