web
You’re offline. This is a read only version of the page.
close
Skip to main content

Announcements

News and Announcements icon
Community site session details

Community site session details

Session Id :
Power Platform Community / Forums / Power Automate / Need a Function to rem...
Power Automate
Unanswered

Need a Function to remove [ ] Square brackets from an array

(0) ShareShare
ReportReport
Posted on by 4

Hello everyone,

I am encountering some issues while attempting to remove the square brackets [ ] from an ARRAY. Here is an example of the scenario:

 

Let's call this array "ContextArray".

 

I am using CHAT-GPT to generate answers based on previous interactions, and the "ContextArray" is placed within an HTTP request. This HTTP request is within a "Do While Loop" because the "ContextArray" will be fed with new responses from chat GPT, and the array will increase from (see image 1) to (see image 2) to (see image 3). However, the HTTP request will only receive the array without the [ ] brackets; otherwise, it will give me an error in the request.

 

I cannot use the array index since I need to display all the objects at once.

 

Is there a way to display all the items within the array? For example, instead of "variables('Array')[0]" or "variables('Array')[1]", something like "variables('Array')[ALL]".

 

I have already attempted to convert the array to a string, but it did not work.

 

Any ideas regarding this matter would be much appreciated. Thank you.

 

Image_1

Danatt_0-1684033082214.png

Image_2

Danatt_1-1684034304565.png

Image_3

Danatt_2-1684034333117.png

 

 

Categories:
I have the same question (0)
  • Nived_Nambiar Profile Picture
    18,136 Super User 2026 Season 1 on at

    Hi @Danatt 

     

    Give a try like this 

     

    replace(replace(string(variables('Array')),'[',''),']','')

     

    Hope it helps 🙂

     

  • Danatt Profile Picture
    4 on at

    Dear @Nived_Nambiar,

     

    Thank you for your response.

     

    I have tried using the function that you suggested, but the Compose output I received is not as expected. While the square brackets were successfully removed, the curly brackets "{ }" are now accompanied by colons and backslashes. 

     

    The desired output should be in the following format:

     

    {"role":"assistant","content":"Respuesta GPT 0"},{"role":"user","content":"Respuesta Votacion 0"}

     

    However, when I incorporate the output of the Compose action in the HTTP request, the result appears as follows:

     

    "{\"role\":\"assistant\",\"content\":\"Respuesta GPT 0\"},{\"role\":\"user\",\"content\":\"Respuesta Votacion 0\"}"
     

    I have attempted to remove the backslashes, as well as the initial and final colon using a replace function, but it appears that these symbols are implicit within the string.

     

    Finally this is the error of the HTTP:

     

    {
      "error": {
        "message": "'{\"role\":\"assistant\",\"content\":\"Test Assistant 0\"},{\"role\":\"user\",\"content\":\"Test Votacion 0\"}' is not of type 'object' - 'messages.2'",
        "type": "invalid_request_error",
        "param": null,
        "code": null
      }
    }
     

    Thank you.

  • Nived_Nambiar Profile Picture
    18,136 Super User 2026 Season 1 on at

    Hi @Danatt 

     

    I saw in openAI Api documentation, messages are passed with square brackets in request body 

     

    Nived_Nambiar_0-1684115163161.png

     

     

    Nived_Nambiar_1-1684115184442.png

     

     

    Hope it helps !

     

    Mark it as solution if it resolves your query !

     

  • Srini007 Profile Picture
    3,453 Super User 2026 Season 1 on at

    @Danatt 

     

    I'm checking with you, Is the Image1, Image2, Image3 are from the same request?

    Can you paste the response in a notepad file and attach here?

     

    Thanks,

    Srini

  • NER Profile Picture
    24 on at

    Thank you for your answer, it works for me. However, if you wish to replace "," is another problem that belongs to the array itself and if your string has any comma for example 15,30. It replaces the string itself also and shows 1530.

  • Chriddle Profile Picture
    8,525 Super User 2026 Season 1 on at

    In most cases, it's not a good idea to perform string manipulations on a JSON (unless you know exactly what you're doing 😉).

     

    Depending on how you want to display the objects, I have two proposals:

    • "Create HTML table"
    • Put the array into a Select, map the objects to strings in the way you want them and in the next action join() these strings.
  • Chriddle Profile Picture
    8,525 Super User 2026 Season 1 on at

    However, if the objects already are in the preferred shape, why not simply join them?

    Chriddle_0-1705669579235.png

     

     

    join(outputs('Compose'), ',')

     

     

     

    Result:

     

     

    {"role":"assistant","content":"R1"},{"role":"assistant","content":"R1"}

     

     

    But it seems that is not your problem anymore 🤣

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Introducing the 2026 Season 1 community Super Users

Congratulations to our 2026 Super Users!

Kudos to our 2025 Community Spotlight Honorees

Congratulations to our 2025 community superstars!

Leaderboard > Power Automate

#1
David_MA Profile Picture

David_MA 60 Super User 2026 Season 1

#2
Haque Profile Picture

Haque 54

#3
Expiscornovus Profile Picture

Expiscornovus 47 Most Valuable Professional

Last 30 days Overall leaderboard