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 / How to extract 1st obj...
Power Automate
Answered

How to extract 1st object from an array of objects ?

(1) ShareShare
ReportReport
Posted on by 20

Hi, 

I have a JSON file which gives me an array of objects.
But i need only 1st object from it dynamically.

{
"LastAggregationDate": "2023-09-28T14:15:39.7134477+04:00",
"Connectors": {
"Snow Xml_1": [
{
"AggregationId": "a53e4b38-3458-4636-8cdb-b524b08d598b",
"AggregationDate": "2023-09-08T15:06:07.0510562+04:00",
"ProviderName": "XmlInventoryProvider",
"InstanceName": "Snow Xml_1",
"Trigger": "Manual",
"State": "Completed"
},
{
"AggregationId": "270da50a-c6a0-446e-9950-006ce4d789c7",
"AggregationDate": "2023-09-08T14:48:41.1524499+04:00",
"ProviderName": "XmlInventoryProvider",
"InstanceName": "Snow Xml_1",
"Trigger": "Manual",
"State": "Completed"
}
]

Here i only need the first object as an output without hardcoding the array name.



Categories:
I have the same question (0)
  • efialttes Profile Picture
    14,756 on at

    Hi @Vaheeth_Raj 
    first() WDL expression would do the trick
    I am using "Initialize variable" to store temporarily your input array, but this step is not strictly needed

    efialttes_0-1696945836807.png

     


    More examples here:
    https://www.c-sharpcorner.com/article/usage-of-first-and-last-function-in-power-automate/
    Hope this helps
    ===========

  • trice602 Profile Picture
    16,071 Super User 2026 Season 1 on at

    Hi @Vaheeth_Raj ,

     

    You can use the expression first() to accomplish this.  Here I put your json output in a compose action.  In the following action, I use first(outputs('Compose')) to get the first item.

     

    trice602_0-1696945181282.png

     

     

    trice602_1-1696945227381.png

     

     

  • Vaheeth_Raj Profile Picture
    20 on at

    Hi , Thanks for the reply, Still facing problem.

    Let me explain my problem to you clearly.
    In my JSON Output, I have many arrays . Inside each array there are nested objects. 
    My requirement is I need to get the first object from each array without hardcoding the array name.
    when i give the JSON input it should give me the first object from all arrays as an output.

    Screenshot 2023-10-11 102343.pngScreenshot 2023-10-11 102542.png

    Below is my JSON file.

    [

    "Snow SLM Data Exporter_1": [
    {
    "AggregationId": "7880878f-49bf-4def-94bc-6dc28479fe70",
    "AggregationDate": "2021-07-28T13:20:18.534574+04:00",
    "ProviderName": "SlmExporterInventoryDataProvider",
    "InstanceName": "Snow SLM Data Exporter_1",
    "Trigger": "Manual",
    "State": "Completed"
    }
    ],
    "SaaS - Generic connector_1": [
    {
    "AggregationId": "36355e15-2e95-4d41-ae08-5451cfeae2d1",
    "AggregationDate": "2023-05-11T16:45:36.3546592+04:00",
    "ProviderName": "GenericSaaSInventoryProvider",
    "InstanceName": "SaaS - Generic connector_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "33c58575-295d-4f51-a532-8334c6f42d54",
    "AggregationDate": "2023-02-27T10:42:46.2403684+04:00",
    "ProviderName": "GenericSaaSInventoryProvider",
    "InstanceName": "SaaS - Generic connector_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "b6bf83db-b30f-4527-b308-ecac8dc0325b",
    "AggregationDate": "2023-02-27T10:30:41.7956151+04:00",
    "ProviderName": "GenericSaaSInventoryProvider",
    "InstanceName": "SaaS - Generic connector_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "968a1dd6-6548-4c7c-8985-e6a39978f812",
    "AggregationDate": "2023-02-27T10:28:33.7246595+04:00",
    "ProviderName": "GenericSaaSInventoryProvider",
    "InstanceName": "SaaS - Generic connector_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "de483173-7e42-4370-a87a-742dc9824b36",
    "AggregationDate": "2023-02-27T09:57:35.9075782+04:00",
    "ProviderName": "GenericSaaSInventoryProvider",
    "InstanceName": "SaaS - Generic connector_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "3319e70f-73d4-4231-8c25-b472fbac6e77",
    "AggregationDate": "2023-02-27T09:55:30.2813283+04:00",
    "ProviderName": "GenericSaaSInventoryProvider",
    "InstanceName": "SaaS - Generic connector_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "ecc7c8bd-1df4-40c5-91ab-0cbeb870608c",
    "AggregationDate": "2023-02-27T09:55:20.6601868+04:00",
    "ProviderName": "GenericSaaSInventoryProvider",
    "InstanceName": "SaaS - Generic connector_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "274df8bd-a288-48a4-8158-b6ee9d8dd1e7",
    "AggregationDate": "2023-02-27T09:51:25.5612774+04:00",
    "ProviderName": "GenericSaaSInventoryProvider",
    "InstanceName": "SaaS - Generic connector_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "7bce33b4-3910-40ee-b075-c2e89af9ffac",
    "AggregationDate": "2022-12-29T11:14:09.6267255+04:00",
    "ProviderName": "GenericSaaSInventoryProvider",
    "InstanceName": "SaaS - Generic connector_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "e765ae5e-e112-4dd8-a43c-102196d260ee",
    "AggregationDate": "2022-12-28T10:02:05.1194557+04:00",
    "ProviderName": "GenericSaaSInventoryProvider",
    "InstanceName": "SaaS - Generic connector_1",
    "Trigger": "Manual",
    "State": "Completed"
    }
    ],
    "Snow Xml_Test": [
    {
    "AggregationId": "8d1e86bd-42c3-4fe2-8ef2-f5d430b84cbe",
    "AggregationDate": "2021-10-25T10:42:07.0295285+04:00",
    "ProviderName": "XmlInventoryProvider",
    "InstanceName": "Snow Xml_Test",
    "Trigger": "Manual",
    "State": "Completed"
    }
    ],
    "IBM License Metric Tool_1": [
    {
    "AggregationId": "e52051ce-4aaa-4fc5-b4df-446cafce3b1b",
    "AggregationDate": "2022-07-25T13:03:07.2586885+04:00",
    "ProviderName": "IlmtInventoryProvider",
    "InstanceName": "IBM License Metric Tool_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "e5fe16ba-3033-403d-8a39-423e0c8ecf7d",
    "AggregationDate": "2022-07-06T12:34:12.2348714+04:00",
    "ProviderName": "IlmtInventoryProvider",
    "InstanceName": "IBM License Metric Tool_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "cc75ac39-c71f-4144-a601-6bdbb0c91c82",
    "AggregationDate": "2022-07-06T10:20:45.334396+04:00",
    "ProviderName": "IlmtInventoryProvider",
    "InstanceName": "IBM License Metric Tool_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "24aa76e1-2353-447e-b5d6-bc04c958e142",
    "AggregationDate": "2022-07-01T14:18:31.7118513+04:00",
    "ProviderName": "IlmtInventoryProvider",
    "InstanceName": "IBM License Metric Tool_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "19230d53-6172-4aa2-ac03-7b8ddc4b58be",
    "AggregationDate": "2022-06-30T12:26:10.8775376+04:00",
    "ProviderName": "IlmtInventoryProvider",
    "InstanceName": "IBM License Metric Tool_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "da90ce95-a656-413c-b9b6-a35b57005384",
    "AggregationDate": "2022-06-29T09:45:42.0808761+04:00",
    "ProviderName": "IlmtInventoryProvider",
    "InstanceName": "IBM License Metric Tool_1",
    "Trigger": "Manual",
    "State": "Completed"
    },
    {
    "AggregationId": "b4e8ea21-f9b4-415f-b263-99cf74a37692",
    "AggregationDate": "2022-06-29T09:28:20.2766687+04:00",
    "ProviderName": "IlmtInventoryProvider",
    "InstanceName": "IBM License Metric Tool_1",
    "Trigger": "Manual",
    "State": "Completed"
    }
    ]
     
     
    I want the output like this without hardcoding any array names.


    [
    "Snow SLM Data Exporter_1": [
    {
    "AggregationId": "7880878f-49bf-4def-94bc-6dc28479fe70",
    "AggregationDate": "2021-07-28T13:20:18.534574+04:00",
    "ProviderName": "SlmExporterInventoryDataProvider",
    "InstanceName": "Snow SLM Data Exporter_1",
    "Trigger": "Manual",
    "State": "Completed"
    }
    ],
    "SaaS - Generic connector_1": [
    {
    "AggregationId": "36355e15-2e95-4d41-ae08-5451cfeae2d1",
    "AggregationDate": "2023-05-11T16:45:36.3546592+04:00",
    "ProviderName": "GenericSaaSInventoryProvider",
    "InstanceName": "SaaS - Generic connector_1",
    "Trigger": "Manual",
    "State": "Completed"
    }
    ],
    "Snow Xml_Test": [
    {
    "AggregationId": "8d1e86bd-42c3-4fe2-8ef2-f5d430b84cbe",
    "AggregationDate": "2021-10-25T10:42:07.0295285+04:00",
    "ProviderName": "XmlInventoryProvider",
    "InstanceName": "Snow Xml_Test",
    "Trigger": "Manual",
    "State": "Completed"
    }
    ]
  • efialttes Profile Picture
    14,756 on at

    @Vaheeth_Raj 
    Oooops! So you have an input JSON object, with several attributes all of them of type array, each of these arrays have 1..n elements, right? And you need to convert it into an object with the same attributes all of them of type array, each of these arrays containing a single element, right?
    And you also need to do it without hardcoding the array names in your WDL expressions...
    I believe this means the array names change from time to time, and you do not want to rewrite the code. If so, I am afraid this is not possible with Power Automate in an elegant easy way... but
    I just checked this post and now think there is an option to do it in a not so elegant but effective way.
    I will work on it and write back with the result

    Just taking your 'Compose 2' as my entry point:

    efialttes_0-1697042758648.png


    =======================================================

  • Vaheeth_Raj Profile Picture
    20 on at

    Hey, thanks for your Response.

    Yes , as u said , u are right. My Key names change dynamically. 


    Happy to know that you are working on it.

    Plz let me know once you are ready with the result, Any doubts, please feel free to knock. Thnx

  • Verified answer
    efialttes Profile Picture
    14,756 on at

    Hi again!
    Close to a happy ending, since I managed to extract the property names and store them into an array

    efialttes_1-1697044054646.png

    This is my Flow design so far:

    efialttes_2-1697044119656.png

    THe WDL expression assigned to 'Initialize variable' action block is:

     

     

     

    reverse(skip(reverse(split(string(outputs('Compose_2')['Connectors']),']')),1))

     

     

     

    I've named the variable as 'myInputPropertiesArray' of type array.

    I've added this variable as 'Select' action block input. Please note I hace clicked on the 'T inside an square' icon on the right, in order to switch into text mode...

    efialttes_4-1697045655558.png

     

    ...then added the  following WDL expression:

     

     

     

    split(first(split(item(),'[')),'"')[1]

     

     

     


    Please follow these first steps and let me now if you get the same results as the ones I shared in my first screenshot!



    So far so good? Great!

    Next, we will add some extra steps
    -A second 'initialize variable' action block, new variable of type object called 'myOutputObject'. I have assigned as its value the folowing WDL expression:

     

     

     

    json('{}')

     

     

     

    -An Apply to each to iterate on the property names, so I assign as its input value the 'Select' action block output

    efialttes_3-1697045390945.png

     


    Now, inside the apply to each I have added:
    -A 'Compose action block' called 'Compose_aux', assigning as its value 'myOutputObject' variable
    -A 'Set variable' action block in order to update this 'myOutputObject' variable, assigning as its new value the following WDL expression:

     

     

     

    setProperty(outputs('Compose_aux'),item(),first(outputs('Compose_2')['Connectors'][item()]))

     

     

     

    Finally, if you add a new Compose action block at the end of your flow, outside the 'Apply to each', and assign as its value 'myOutputObject' variable you can execute the flow and inspect the results
    Hope this helps 
    ==========

  • Vaheeth_Raj Profile Picture
    20 on at

    Hi, 

    From the bottom of my heart !!!
    Keep up the great work !!!
    Thanks a ton !!!

    Just for my understanding, 
    I can come up to the logic that you have used.
    Logic Explanation : Extracting the above property names and storing it in an array format as a variable.
    Then later referring that variable to check for each property name and then extracting the first object. Am i right?

  • Vaheeth_Raj Profile Picture
    20 on at

    Screenshot 2023-10-11 234352.pngScreenshot 2023-10-11 234533.png

  • efialttes Profile Picture
    14,756 on at

    @Vaheeth_Raj wrote:

     

    Just for my understanding, 
    I can come up to the logic that you have used.
    Logic Explanation : Extracting the above property names and storing it in an array format as a variable.
    Then later referring that variable to check for each property name and then extracting the first object. Am i right?


    Yes, you are totally right!
    Compose_2 output is an object with several properties, one of them called Connectors. 
    And, Connectors is also an object with several subproperties, hte ones whose names change from time to time.
    Inside the 'Apply to each' I am reading one by one by means of...

    outputs('Compose_2')['Connectors'][item()]

    ...so each time the loop itearates it translate the wdl expression item() into the corresponding subproperty name.
    The point is, I am assuming all those suproperties are of type array, so I am extracting the first element by means of ...

    first(outputs('Compose_2')['Connectors'][item()])


    Hope this helps
    ==========

  • efialttes Profile Picture
    14,756 on at

    @Vaheeth_Raj 

    So, you managed to overcome the challenge, right?

    Congrats!

     

    Next steps? My humble suggestion is to mark this topic as "Solved" by clicking "Accept as a solution" in my detailed reply. THis way others with the same problem can find a solution faster. Please also note you can even select several responses as solution, even from different community members!

     

    Flow_AcceptSolution.png

     

    Thanx for your help making this community great!

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!

Congratulations to the March Top 10 Community Leaders!

These are the community rock stars!

Leaderboard > Power Automate

#1
Haque Profile Picture

Haque 592

#2
Valantis Profile Picture

Valantis 340

#3
11manish Profile Picture

11manish 284

Last 30 days Overall leaderboard