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 😉

Thank you so much. This was really helpful.

Helpful resources

Announcements
MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

Users online (1,502)