How can I add quotation marks to strings in a string array?

Options
pachocastillosr
pachocastillosr Member
edited August 2023 in ? Help! I'm a Noob

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!

Tagged:

Best Answer

  • arturosanz
    arturosanz Member ✭✭
    Answer ✓
    Options

    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

  • arturosanz
    arturosanz Member ✭✭
    edited August 2023
    Options

    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.

  • pachocastillosr
    Options

    @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?

  • arturosanz
    arturosanz Member ✭✭
    edited August 2023
    Options

    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.

  • pachocastillosr
    Options

    Thank you! @arturosanz