Skip to main content

Notifications

Power Automate - Building Flows
Suggested answer

Append object to array

(0) ShareShare
ReportReport
Posted on by 98
Hi,
I want to get an array like this:
[
  {
    "sender": "Sales",
    "message": "Please clarify",
    "timestamp": "12/11/2024 4:36 PM"
  },
  {
    "sender": "Recipient",
    "message": "This is a risk total.",
    "timestamp": "12/11/2024 4:37 PM"
  }
]

I tried to create Power Automate workflow, but got this:
[
  "{\n    \"sender\": \"Sales\",\n    \"message\": \"Please clarify\",\n    \"timestamp\": \"12/11/2024 4:36 PM\"\n},",
  "{\n    \"sender\": \"Recipient\",\n    \"message\": \"This is a risk total.\",\n    \"timestamp\": \"12/11/2024 4:37 PM\"\n},"
]


This is my flow:



How can I achieve this?







 
  • Suggested answer
    Pstork1 Profile Picture
    Pstork1 64,505 on at
    Append object to array
    The problem is that the values in the Compose will be interpreted as a String, not a JSON array.  Just declare the array in the Initialize Variable action. That will give you the array you want.

    ----------------------------------------------------------------------------------
    If this Post helped you, please click "Does this answer your question" and give it a like to help others in the community find the answer too!

    Paul Papanek Stork, MVP
    Blog: https://www.dontpapanic.com/blog
     
  • Suggested answer
    SpongYe Profile Picture
    SpongYe 5,358 on at
    Append object to array
    Hi @xvzms 
     
    Replace this:
    With this the current item:
     
    My results:
     
     
     
  • Suggested answer
    SwatiSTW Profile Picture
    SwatiSTW 267 on at
    Append object to array
    In your Power Automate flow, use the "Initialize Variable" action. Set the type to Array and name it something like MyArray.
    Use the "Append to Array Variable" action to add objects to the array. For example:
    {
        "sender": "Sales",
        "message": "Please clarify",
        "timestamp": "12/11/2024 4:36 PM"
    }
    Add another similar action for the next object:
    {
        "sender": "Recipient",
        "message": "This is a risk total.",
        "timestamp": "12/11/2024 4:37 PM"
    }
    Make sure you are adding the objects directly as shown above. Do not enclose them in quotes or use any string-related expressions.
    To confirm, add a "Compose" action after you've appended all objects. Use the array variable MyArray in the "Input" field of the Compose action.
    Run the flow. The output from the "Compose" action should now show an array of objects, not strings.

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

Kickstarter Events…

Register for Microsoft Kickstarter Events…

Tuesday Tip #12 Start your Super User…

Welcome to a brand new series, Tuesday Tips…

Tuesday Tip #13 Writing Effective Answers…

Welcome to a brand new series, Tuesday Tips…

Leaderboard

#1
WarrenBelz Profile Picture

WarrenBelz 144,858

#2
RandyHayes Profile Picture

RandyHayes 76,287

#3
Pstork1 Profile Picture

Pstork1 64,505

Leaderboard