cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
rleonen
Frequent Visitor

join consecutive key/value pairs in an array.

Hi,

I have an array of key/value pairs that looks like this:

[
{
"ID": "https://knowledgebase.com/link_to_article_1"
},
{
"Title": "Title of Article 1"
},
{
"ID": "https://knowledgebase.com/link_to_article_2"
},
{

"Title": "Title of Article 2"

}
]

How can I combine consecutive array elements so that it looks like this instead?

[
{
"ID": "https://knowledgebase.com/link_to_article_1",
"Title": "Title of Article 1"
},
{
"ID": "https://knowledgebase.com/link_to_article_2",
"Title": "Title of Article 2"
}
]

1 ACCEPTED SOLUTION

Accepted Solutions

Hi @rleonen 

 

A lot simpler way of doing it, is just by using a select like @ManishJain has suggested and using some of @Paulie78 length logic.  It can be done in one simple action as follows:

 

DamoBird365_0-1626850217288.png

Your from is 

range(0,div(length(outputs('Compose')),2))
which is a range from 0 to the length of the array divided by 2
 
Your ID value is:
outputs('Compose')[mul(item(),2)]?['Id']
which is the range value multiplied by 2, i.e. 0,2,4,6,8 .....
 
Your Title ID is:
 outputs('Compose')[add(mul(item(),2),1)]?['TItle']
which is the same as above +1, i.e. 1,3,5,7,9 ....
 
The flow runs as follows:
DamoBird365_1-1626850360834.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

5 REPLIES 5
ManishJain
Solution Sage
Solution Sage

Hi @rleonen ,

 

You need to use Select action to get the required data. This action maps the data from input to output.

 

in your case all you need to do map like this 

 

ID --> item()?['ID']

Title-->item()?['Title']

 

ManishJain_0-1626815565211.png

 

 

Thanks

 

 

 

That suggestion is close but I don't get the consecutive rows combined into a single element. The output after using the 'Select' action now looks like below. Is there a way to combine the consecutive rows into a single element?

[
  {
    "Title"null
  },
  {
    "ID"null,
    "Title""Document Needs to Have World Read Permission"
  },
  {
    "Title"null
  },
  {
    "ID"null,
    "Title""NAO How to create Jira Change Requests for L&D IT North America team"
  }
]

Take a look at this screenshot (I also included run history on right hand side). It does what you want. If you have any trouble following, I will explain in more detail:

https://ibb.co/v42ZHFZ

 

Blog: tachytelic.net

YouTube: https://www.youtube.com/c/PaulieM/videos

If I answered your question, please accept it as a solution 😘

Hi @rleonen 

 

A lot simpler way of doing it, is just by using a select like @ManishJain has suggested and using some of @Paulie78 length logic.  It can be done in one simple action as follows:

 

DamoBird365_0-1626850217288.png

Your from is 

range(0,div(length(outputs('Compose')),2))
which is a range from 0 to the length of the array divided by 2
 
Your ID value is:
outputs('Compose')[mul(item(),2)]?['Id']
which is the range value multiplied by 2, i.e. 0,2,4,6,8 .....
 
Your Title ID is:
 outputs('Compose')[add(mul(item(),2),1)]?['TItle']
which is the same as above +1, i.e. 1,3,5,7,9 ....
 
The flow runs as follows:
DamoBird365_1-1626850360834.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 😉

Thanks Damien - solution works perfectly!

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.

New Process Advisor Capabilities carousel.png

Read the blog for the latest news

Read the latest about new experiences and capabilities in the Power Automate product blog.

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 (3,198)