cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
sharepointguy
Helper I
Helper I

Array to Object

Hi All,

 

I have the below array which I want to convert in an Object.

 

{

"values": [

  [

   "Header1",

   "Header2"

  ],

  [

   "Value1",

   "Value2"

  ],

  [

   "Value11",

   "Value22"

  ]

 ]

}

 

My desired output is

 

{

  [

     "Header1":"Value1",

     "Header2":"Value2",

  ],

  [

     "Header1":"Value11",

     "Header2":"Value22",

  ]

}

 

Any help would be appreciated.

1 ACCEPTED SOLUTION

Accepted Solutions
DamoBird365
Super User
Super User

Hi @sharepointguy 

 

That's a very peculiar looking array of arrays!  An array of objects would be easier, saying that, this is possible with a select.

 

From: range(1,add(length(outputs('Compose')?['values']),-1))

which is basically skip integer 0 (the header) and run til length of values array minus 1

 

keys are:

outputs('Compose')?['values']?[0]?[0]
outputs('Compose')?['values']?[0]?[1]
values are:
outputs('Compose')?['values']?[item()]?[0]
outputs('Compose')?['values']?[item()]?[1]
 
I stuck your array into a compose
DamoBird365_1-1629318575876.png

 

and converted it as requested....

 
DamoBird365_0-1629318553158.png

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

View solution in original post

2 REPLIES 2
DamoBird365
Super User
Super User

Hi @sharepointguy 

 

That's a very peculiar looking array of arrays!  An array of objects would be easier, saying that, this is possible with a select.

 

From: range(1,add(length(outputs('Compose')?['values']),-1))

which is basically skip integer 0 (the header) and run til length of values array minus 1

 

keys are:

outputs('Compose')?['values']?[0]?[0]
outputs('Compose')?['values']?[0]?[1]
values are:
outputs('Compose')?['values']?[item()]?[0]
outputs('Compose')?['values']?[item()]?[1]
 
I stuck your array into a compose
DamoBird365_1-1629318575876.png

 

and converted it as requested....

 
DamoBird365_0-1629318553158.png

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Cheers,
Damien


P.S. take a look at my new blog here and like & subscribe to my YouTube Channel thanks 😉

View solution in original post

Thank you so much. This was really helpful.

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,525)