2 weeks ago
Is there a formula that can be used to convert list of String variables to a list of integers ?
I/P is ["1","100","50", "4"]
O/P [1,100,50,4]
Solved! Go to Solution.
a week ago
Hi @shefali,
If you observe my screenshots:
1๏ธโฃ In the 2nd and 3rd images,
I used Variable_name: List and Datatype: String. When applying the pluck("v") formula, it automatically converts to List_of_Numbers, so there's no need to explicitly set the data type as List.
2๏ธโฃ I have a small curiosity: Why do we need to create two variables with Integer or Number data types to parse a number list?
Answer: There's no need to use two variables. As I suggested, when we apply the pluck("v") formula, it automatically takes care of converting to List_of_Numbers.
3๏ธโฃ However, when using list functions, it still treats the variable as a list. Shouldn't it actually be recognized as a number instead?
Could you please share a screenshot? I didnโt fully understand your point here.
Looking forward to your insights! ๐
Thanks and Regards,
Shivakumar K A
a week ago
Hi Prudvi,
Here is my sample JSON that needs to be parsed. I am first parsing the given JSON. Then, I use TestValueSampleList.pluck("v") to extract a list of strings, which I then convert into a list of integers using native functions and formulas.
{
"TestValueSample": [
{
"k1": "t1",
"v": "9"
},
{
"k1": "t2",
"v": "11"
},
{
"k1": "t3",
"v": "21"
},
{
"k1": "t4",
"v": "7"
}
]
}
a week ago
Hi @shefali ,
Here, I am adding a screenshot after parsing the provided JSON.
- 2nd Image: The input hasnโt been explicitly converted to an integer, yet the output is a list of integers.
- 4th Image: If this doesn't work on your end, you can use another variable of type "Integer" and pass the output from the `pluck("v")` formula.
Thanks and Regards,
Shivakumar
a week ago
Thanks, Shiva! Your solution worked perfectly for meโI really appreciate it.
I do have a small curiosity: Why do we need to create two variables of integer or number data type to parse a number list? For example, after the JSON parse step, I attempted to create a list of numbers, and the output appeared as expectedโa list of numbers. However, when using list functions, it still treats the variable as a list. Shouldn't it actually be recognized as a number instead?
Is this the expected behavior of the function, or could it be a bug? It feels a bit misleading and requires a lot of trial and error to get right
a week ago
Hi @shefali,
If you observe my screenshots:
1๏ธโฃ In the 2nd and 3rd images,
I used Variable_name: List and Datatype: String. When applying the pluck("v") formula, it automatically converts to List_of_Numbers, so there's no need to explicitly set the data type as List.
2๏ธโฃ I have a small curiosity: Why do we need to create two variables with Integer or Number data types to parse a number list?
Answer: There's no need to use two variables. As I suggested, when we apply the pluck("v") formula, it automatically takes care of converting to List_of_Numbers.
3๏ธโฃ However, when using list functions, it still treats the variable as a list. Shouldn't it actually be recognized as a number instead?
Could you please share a screenshot? I didnโt fully understand your point here.
Looking forward to your insights! ๐
Thanks and Regards,
Shivakumar K A
a week ago
Hi Shiva,
Sure. My previous comment was about whether it's possible to apply pluck and min on the same list. For example: TestSample.pluck('v').min(). Currently, this operation works based on ASCII character calculation when applied to strings. To get the maximum integer value, we first need to create a list of strings/integers and then use a variable of type integer to extract the maximum value.
Thanks for your help anyway. Appreciate it
That was the reason for my question. We can mark this as resolved if thereโs no way to apply pluck and max on integers in the same step.