How can I add quotation marks to strings in a string array?
![pachocastillosr](https://us.v-cdn.net/6037124/uploads/userpics/MC7ELS8NG1HC/nPLP98RNMYYEZ.jpg)
Hi,
I have this array of strings:
[aw654, grw68, 4]
This is what I want:
["aw654", "grw68", "4"]
How can I do this in Xano? Is there a filter that can add the quotation marks?
Thanks!
Best Answer
-
To insert the double quote character you can use the escape character \, so you can make a string of just a single double quote like this "\"".
If you have access to lambda functions (available in Xano's paid plans) you can easily transform the elements of the array by applying the
map
filter to your array of strings, concatenating the double quotes at the beginning and at the end.This would be the lambda (javascript) function:
return "\""+$this+"\""
If you don't have access to lambda functions you can use a loop to get the same result, and you won't need to use the backslash character. See the screenshots below.
Answers
-
Just use the escape character \ before any " you want to treat as text.
This is a valid JSON:
{"my_array": ["\"aw654\"","\"grw68\"","\"4\""]}
Now
my_array
contains["aw654", "grw68", "4"]
Of course you can easily automate adding
\"
in Xano if you need to. -
@arturosanz thanks for replying. I am afraid I did not understand your explanation. I'll re write my question to make it clearer.
I have this array of strings:
[aw654, grw68, 4]
I want Xano to transform it into:
["aw654", "grw68", "4"]
How can I do it? -
I showed you how to do it in the previous reply. You can check it out in the screenshots. The function starts with a variable = [aw654, grw68, 4] and the result of the function is ["aw654", "grw68", "4"]. It's just a simple function with a loop and concatenation filters applied to each array item.
-
Thank you! @arturosanz
Categories
- All Categories
- 53 ? Announcements
- 47 ? Releases
- 37 ? Welcome
- 983 ? Help! I'm a Noob
- 125 ? No-Code Front-Ends
- 633 ? Working with APIs
- 439 ? Transforming data
- 126 ? Connect Xano to ...
- 50 ?? Find an Expert
- 348 ❓Other questions
- 35 ? Security
- 22 ✂️ Snippets
- 19 ? Showcase
- 7 ?️ Xano Chatter
- 62 ? Video Tutorials
- 171 ? Request a feature
- 229 ? Report a Bug
- 19 ? Templates & Extensions
- 7 ? Feedback