cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
Julian1
Level: Powered On

Transform Excel Table to a JSON with an embedded Array / Repeatgroup

Hi Guys... I try to make it really short.

 

I am trying to come from

-> this Excelfile:

https://i.imgur.com/Y0aKWmu.png

 

-> To this JSON File: 

{
"No" : "1",
"Task" : "Clean House",
"Description" : "Cleaning",
"Repeatgroup": [
	{
	"Subtask_Location": "X",
	"Subtask_Content": "X",
	"Subtask_Status": "X"
	},
	{
	"Subtask_Location": "Y",
	"Subtask_Content": "Y",
	"Subtask_Status": "Y"
	},
	{
	"Subtask_Location": "Z",
	"Subtask_Content": "Z",
	"Subtask_Status": "Z"
	}
    ],
"Date" : "11/04/19",
"Time" : "00:00"
}

 

My Problem is, that I don't know how to build the Repeatgroup of the JSON file.

  • The reference/indicator is the "No" Field in the Excel-File...
  • So the Values of the 3 "Subtask_..."-Columns need to get written as the Repeatgroup, because of the same "No." (First column) as an indicator...

 

I hope I explained it good. Sorry for bad english, not a native speaker...

 

ANY Help is appreciated very much... For fast and effective help I will give out Tip-Money, since I am so clueless right now and need this to be done. :)) Thank you in Advance

1 ACCEPTED SOLUTION

Accepted Solutions
Community Support Team
Community Support Team

Re: Transform Excel Table to a JSON with an embedded Array / Repeatgroup

Hi @Julian1,

 

I create a whole Flow process that gets the row of Excel file, then create a JSON file for each No.

For the Repeatgroup, you could initialize a variable named Repeategroup, and you can see more details on step 4:

 

This is my whole steps of the Flow:

image 1: all steps

Annotation 2019-09-26 153440.pngimage 2: all stepsAnnotation 2019-09-26 153609.png

Step 1: (image 1)

Initialize variables Clean (to store JSON data), Repeatgroup (to store repeat group) and ALLNo ( to store ALL No, including repeat No), then get the list rows present in a table.

Step 2: (image 2)

Add apply to each and Append to array actions to get the all No of the rows

Step 3: (image 3)

Add expression union(variables('ALLNo'),variables('ALLNo')) into the Big Apply to each No action to get each No and loop it. Then add Apply to each row of table action to get all rows with the same No, append the Repeategroup. After that, we can get Repeategroup array like:

[
	{
	"Subtask_Location": "X",
	"Subtask_Content": "X",
	"Subtask_Status": "X"
	},
	{
	"Subtask_Location": "Y",
	"Subtask_Content": "Y",
	"Subtask_Status": "Y"
	},
	{
	"Subtask_Location": "Z",
	"Subtask_Content": "Z",
	"Subtask_Status": "Z"
	}
    ]

Image 3:

Annotation 2019-09-26 153741.png

Step 4: (image 4)

Add Apply to each row of table-2 action to get rows with same No, set the clean variable as below, since the date in Excel file will return a number that since 1899-12-30, so we should use the addDays function to get the right format:

addDays('1899-12-30', int(item()?['Date']), 'yyyy-MM-dd')

Then create JSON file.

Image 4: 

Annotation 2019-09-26 153804.png

 

Step 5:

After creating a JSON file with the same No, empty the variable Clean and Repeatgroup.Annotation 2019-09-26 153842.png

For the situation that step 4 will fail when some date value is empty, so we should configure the Set variable Repeategroup Null action setting as when the previous step has failed:Annotation 2019-09-26 160721.png

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

1 REPLY 1
Community Support Team
Community Support Team

Re: Transform Excel Table to a JSON with an embedded Array / Repeatgroup

Hi @Julian1,

 

I create a whole Flow process that gets the row of Excel file, then create a JSON file for each No.

For the Repeatgroup, you could initialize a variable named Repeategroup, and you can see more details on step 4:

 

This is my whole steps of the Flow:

image 1: all steps

Annotation 2019-09-26 153440.pngimage 2: all stepsAnnotation 2019-09-26 153609.png

Step 1: (image 1)

Initialize variables Clean (to store JSON data), Repeatgroup (to store repeat group) and ALLNo ( to store ALL No, including repeat No), then get the list rows present in a table.

Step 2: (image 2)

Add apply to each and Append to array actions to get the all No of the rows

Step 3: (image 3)

Add expression union(variables('ALLNo'),variables('ALLNo')) into the Big Apply to each No action to get each No and loop it. Then add Apply to each row of table action to get all rows with the same No, append the Repeategroup. After that, we can get Repeategroup array like:

[
	{
	"Subtask_Location": "X",
	"Subtask_Content": "X",
	"Subtask_Status": "X"
	},
	{
	"Subtask_Location": "Y",
	"Subtask_Content": "Y",
	"Subtask_Status": "Y"
	},
	{
	"Subtask_Location": "Z",
	"Subtask_Content": "Z",
	"Subtask_Status": "Z"
	}
    ]

Image 3:

Annotation 2019-09-26 153741.png

Step 4: (image 4)

Add Apply to each row of table-2 action to get rows with same No, set the clean variable as below, since the date in Excel file will return a number that since 1899-12-30, so we should use the addDays function to get the right format:

addDays('1899-12-30', int(item()?['Date']), 'yyyy-MM-dd')

Then create JSON file.

Image 4: 

Annotation 2019-09-26 153804.png

 

Step 5:

After creating a JSON file with the same No, empty the variable Clean and Repeatgroup.Annotation 2019-09-26 153842.png

For the situation that step 4 will fail when some date value is empty, so we should configure the Set variable Repeategroup Null action setting as when the previous step has failed:Annotation 2019-09-26 160721.png

 

Best Regards,
Community Support Team _ Lin Tu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
thirdimage

Power Automate Community User Group Member Badge

Fill out a quick form to claim your user group badge now!

firstImage

Incoming: New and improved badges!

We've given our badges an overhaul and also added some brand new ones!

fifthimage

Microsoft Learn

Learn how to build the business apps that you need.

sixthImage

Power Platform World Tour

Find out where you can attend!

seventhimage

Webinars & Video Gallery

Watch & learn from the Power Automate Community Video Gallery!

Top Kudoed Authors
Users Online
Currently online: 226 members 5,553 guests
Please welcome our newest community members: