cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
LyCo
Regular Visitor

Data Table to JSON object in PAD

Hi!

 

I have a data table (in Excel) that I need to send via an API call (invoke web action) in Power Automate Desktop.

 

Is there an easy way to convert this table to a JSON object? Or how is this usually handled in similar situations when data needs to get passed via this action?

 

Also, I noticed that in Winautomation there were the features of creating a new custom object and adding a new property to a custom object. Has this action been removed in PAD?

 

Thanks in advance for any input.

1 ACCEPTED SOLUTION

Accepted Solutions
Anonymous
Not applicable

Power Automate Desktop is able to convert a custom object's property with datatable/datarow in it straight into JSON.

You can create a custom object with:

 

 

 

%NewVar% = %{{ }}%

 

 

 

Then create a new property and assign your datatable (note that if property does not exist, it creates it for you in the object. That is why there is no command 'add property to custom object').

 

 

 

%NewVar['Table']% = %Table%

 

 

 

Then you can convert your custom object to JSON with the command 'Convert custom object to JSON'. The result will be a list of objects.

View solution in original post

32 REPLIES 32
Anonymous
Not applicable

Power Automate Desktop is able to convert a custom object's property with datatable/datarow in it straight into JSON.

You can create a custom object with:

 

 

 

%NewVar% = %{{ }}%

 

 

 

Then create a new property and assign your datatable (note that if property does not exist, it creates it for you in the object. That is why there is no command 'add property to custom object').

 

 

 

%NewVar['Table']% = %Table%

 

 

 

Then you can convert your custom object to JSON with the command 'Convert custom object to JSON'. The result will be a list of objects.

LyCo
Regular Visitor

Ok, makes sense! Thanks a lot!

@Anonymous - Thanks for the solution. 

 

Could you please explain a bit more, I am in need of this solution. I have a two dimensional data table in PAD and have to pass this data table object or JSON to power automate to parse. 

@vamsi_varanasi, it is quite straight forward. When you have a table in a variable (e.g. %Table%), you can simply push it into a custom object and then convert it to Json.

 

Here's a quick sample. I created a simple Excel file with the following table:

KeyValue
One1
Two2
Three3

 

I then read the file, extracting data so that the first row is a header row. Here's the result from PAD:

AgniusBartninka_0-1635580375713.png

I then used the following three actions (you can copy and paste this directly to PAD):

 

SET NewVar TO {{ }}
SET NewVar['Table'] TO Table
Variables.ConvertCustomObjectToJson CustomObject: NewVar Json=> CustomObjectAsJson

 

Looks like this in PAD:

AgniusBartninka_1-1635580441905.png

 

What it does is as follows:

  1. Create a new empty custom object named %NewVar% (you don't really need to create a new object if you already have one, though)
  2. Add a property named 'Table' to the custom object with %Table% as its value*
  3. Convert the custom object to Json

Note: If you already have a property with the same name in the object, it will be overwritten. If you do not, it will be added as a new property.

 

The custom object (%NewVar%) will look like this:

AgniusBartninka_2-1635580759102.png

The 'Table' property inside of it will look like this:

AgniusBartninka_3-1635580784145.png

And the Json data after conversion (%CustomObjectAsJson%) will look like this:

 

{"Table":[{"Key":"One","Value":"1"},{"Key":"Two","Value":"2"},{"Key":"Three","Value":"3"}]}

 

As you can see, it basically is converted into a list of objects, with each row being a list item, and each value being added with the column names as keys.

This can then easily be parsed by Power Automate.

-------------------------------------------------------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
Regards, Agnius Bartninkas

Thank you very much for your explanation @Agnius .

 

My data table is below ( two dimensional table ) which contained 50 records 

 

vamsi_varanasi_0-1635589704594.png

 

I hope the same below syntax should work for above table as well.  Please correct me if I am wrong.

 

vamsi_varanasi_1-1635589801016.png

 

Do you have any suggestion how to delete any specific row from  above data table ?

 

Thanks,

 

It should definitely work, with the exception that you need to use proper variable names. Mine were just examples.

As for deleting rows from a table - there is no action that would allow doing it. If you want to do that, the only viable option is instead of pushing the entire table into the object, instead create a new separate list, loop through the rows of the table and add the relevant rows to this list, while skipping those that are irrelevant. You can then add the list of rows into the object and convert it to JSON. The end result will be exactly the same, but with less rows (excluding those you skipped in the loop).

-------------------------------------------------------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
Regards, Agnius Bartninkas

Thanks @Agnius , do we need to create a empty list ( %List[]%) or do we need to create a Empty Data table ( %Table[][]%) to push the specific records ?

That is up to you, but since your goal is converting it to JSON, you are perfectly fine with having an empty list and pushing data table rows as list items into the list. This is because as soon as you convert it from a custom object to JSON, you will anyway end up with having a list of objects. Attempting to create a new table and then push values to each column in each row will simply make your flow more complex without bringing any added benefit.

-------------------------------------------------------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
Regards, Agnius Bartninkas

Thank you again @Agnius .

 

vamsi_varanasi_0-1635601885023.png

 

When I am following the same steps, I am facing the below issue while assigning the list to the custom object ? do you think what could be the issue ?

 

Well, the error is quite self explanatory - the variable does not exist, meaning you have not created the object, before trying to add the property to it.

-------------------------------------------------------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
Regards, Agnius Bartninkas

@Agnius - Sorry, I had overlooked. able to resolve. I got the below format in Power Automate. 

do you think the below JSON format is correct as the format you have posted in your example was different.

 

it has Row Error , RowState , etc and these are not from my fields. 

 

 

 

vamsi_varanasi_0-1635605021661.png

 

Yes, apparently Data Row objects have some additional parameters that are not visible (nor accessible), unless you put it into an object and then convert to JSON. It is perfectly fine to go with this - it looks different than the other format, but it still is a valid JSON string that you can parse in Power Automate.

 

Alternatively, if you want to avoid having those extra values, you could pick out the explicit values you need, convert it to an object and add the object to the list, instead of the whole data row. For instance, my table has two columns: "Key" and "Value", so, instead of putting the whole data row into a list of data rows, I can put 

 

{'Key': '%Row['Key']%', 'Value': '%Row['Value']%'}

 

to the list. This is basically a JSON string already, that contains the column names and the values for each column.

If you have a dynamic data table with an unspecified number of columns, you can also loop through those. Also, if your columns are not named, you can use indexes instead of column names:

 

{'Key': '%Row[0]%', 'Value': '%Row[1]%'}

 

If you put this into a Convert JSON to custom object action and then add the output of that action to the list, you will end up with something like this after you convert %NewVar% back to JSON:

 

{"List":[{"Properties":{"Key":"One","Value":"1"}},{"Properties":{"Key":"Two","Value":"2"}},{"Properties":{"Key":"Three","Value":"3"}}]}

 

 

Please note, that the "Properties" part of this is actually a known existing bug in PAD, that is added when you convert a custom object that contains a list of objects to JSON. MS is working on fixing this in the next release. If you want to avoid this, you would need to replace this before passing it as output to PA.

 

The above is, however, basically a pretty ugly workaround. My suggestion would be passing the entire table the way it was shown earlier to PA and then using PA logic to skip irrelevant lines.

-------------------------------------------------------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
Regards, Agnius Bartninkas

Thank you again @Agnius .

Let me test this end to end and share you the results. 

Hi @Agnius 

I am new to power automate.

Can you suggest me how to extract values from json as per key in PAD?

Hello and welcome,

In order to extract values from JSON, you would first need to convert the JSON string to an object in PAD by using the 'Convert JSON to custom object' action.

For instance, here's a simple code that

  1. creates a JSON string as {'Key': 'Value'} and stores it in a variable called %JSON%
  2. converts the string to a custom object and stores the object into %CustomObject%
  3. retrieves the value of the 'Key' element from the object and stores it into %Value%

 

SET JSON TO $'''{\'Key\': \'Value\'}'''
Variables.ConvertJsonToCustomObject Json: JSON CustomObject=> CustomObject
SET Value TO CustomObject['Key']

 The syntax is simple - %Object['Key']%.

 

Note: If the key is a variable, you do not need the single quotes. Those are used to pass in a literal value.

 

Also, the same works for adjusting a value of an object, or adding a new property with a value.

For instance, the following code would change the value of the same 'Key' in the object with 'value2':

SET CustomObject['Key'] TO $'''value2'''

And if the Key you are trying to set does not exist, it will be added. So, the following code would add a new property called "Key2" with a value "Value2" to the object:

SET CustomObject['Key2'] TO $'''Value2'''
-------------------------------------------------------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
Regards, Agnius Bartninkas
Anonymous
Not applicable

Awesome Contents. I just learn something new about PAD today regarding create a custom object to an empty variable.

takolota
Multi Super User
Multi Super User

Thanks @Agnius,

 

I was looking for any better ways to pass large tables of data from Power Automate Desktop to cloud flows to SharePoint. This thread seems to explain some of the current state of PAD data-tables to JSON. It would be nice if there was an efficient way to convert large datasets to JSON before sending to cloud flows as that would avoid possible other parsing issues with in-data commas. But if I understood this thread correctly, it sounds like my current set-up, parsing everything from CSV type tables/strings in the cloud flows is more efficient.

 

https://powerusers.microsoft.com/t5/Power-Automate-Cookbook/Automate-Reports-From-External-Datasourc...

I get errors when converting datatable into JSON. I followed steps explained by @Agnius

muhammednihad_0-1667959197630.png

Errors:

muhammednihad_1-1667959267314.png

Where did I go wrong?🤔

What I need to achieve is: When an update, insert, or delete happens on an SQL database table, need to fetch those data and convert into JSON then pass it into API.

Quick help needed. Thanks❤️

Seems to me the syntax in your Set variable action (action #4) is incorrect.

Please make sure you use the following value to set the variable:

%{{ }}%

 This will create a custom object.

-------------------------------------------------------------------------------------------------------------------------
If I have answered your question, please mark it as the preferred solution. If you like my response, please give it a Thumbs Up.
Regards, Agnius Bartninkas

Helpful resources

Announcements

Community will be READ ONLY July 16th, 5p PDT -July 22nd

Dear Community Members,   We'd like to let you know of an upcoming change to the community platform: starting July 16th, the platform will transition to a READ ONLY mode until July 22nd.   During this period, members will not be able to Kudo, Comment, or Reply to any posts.   On July 22nd, please be on the lookout for a message sent to the email address registered on your community profile. This email is crucial as it will contain your unique code and link to register for the new platform encompassing all of the communities.   What to Expect in the New Community: A more unified experience where all products, including Power Apps, Power Automate, Copilot Studio, and Power Pages, will be accessible from one community.Community Blogs that you can syndicate and link to for automatic updates. We appreciate your understanding and cooperation during this transition. Stay tuned for the exciting new features and a seamless community experience ahead!

Summer of Solutions | Week 4 Results | Winners will be posted on July 24th

We are excited to announce the Summer of Solutions Challenge!    This challenge is kicking off on Monday, June 17th and will run for (4) weeks.  The challenge is open to all Power Platform (Power Apps, Power Automate, Copilot Studio & Power Pages) community members. We invite you to participate in a quest to provide solutions to as many questions as you can. Answers can be provided in all the communities.    Entry Period: This Challenge will consist of four weekly Entry Periods as follows (each an “Entry Period”)   - 12:00 a.m. PT on June 17, 2024 – 11:59 p.m. PT on June 23, 2024 - 12:00 a.m. PT on June 24, 2024 – 11:59 p.m. PT on June 30, 2024 - 12:00 a.m. PT on July 1, 2024 – 11:59 p.m. PT on July 7, 2024 - 12:00 a.m. PT on July 8, 2024 – 11:59 p.m. PT on July 14, 2024   Entries will be eligible for the Entry Period in which they are received and will not carryover to subsequent weekly entry periods.  You must enter into each weekly Entry Period separately.   How to Enter: We invite you to participate in a quest to provide "Accepted Solutions" to as many questions as you can. Answers can be provided in all the communities. Users must provide a solution which can be an “Accepted Solution” in the Forums in all of the communities and there are no limits to the number of “Accepted Solutions” that a member can provide for entries in this challenge, but each entry must be substantially unique and different.    Winner Selection and Prizes: At the end of each week, we will list the top ten (10) Community users which will consist of: 5 Community Members & 5 Super Users and they will advance to the final drawing. We will post each week in the News & Announcements the top 10 Solution providers.  At the end of the challenge, we will add all of the top 10 weekly names and enter them into a random drawing.  Then we will randomly select ten (10) winners (5 Community Members & 5 Super Users) from among all eligible entrants received across all weekly Entry Periods to receive the prize listed below. If a winner declines, we will draw again at random for the next winner.  A user will only be able to win once overall. If they are drawn multiple times, another user will be drawn at random.  Individuals will be contacted before the announcement with the opportunity to claim or deny the prize.  Once all of the winners have been notified, we will post in the News & Announcements of each community with the list of winners.   Each winner will receive one (1) Pass to the Power Platform Conference in Las Vegas, Sep. 18-20, 2024 ($1800 value). NOTE: Prize is for conference attendance only and any other costs such as airfare, lodging, transportation, and food are the sole responsibility of the winner. Tickets are not transferable to any other party or to next year’s event.   ** PLEASE SEE THE ATTACHED RULES for this CHALLENGE**   Week 1 Results: Congratulations to the Week 1 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge.   Community MembersNumber SolutionsSuper UsersNumber Solutions Deenuji 9 @NathanAlvares24  17 @Anil_g  7 @ManishSolanki  13 @eetuRobo  5 @David_MA  10 @VishnuReddy1997  5 @SpongYe  9JhonatanOB19932 (tie) @Nived_Nambiar  8 @maltie  2 (tie)   @PA-Noob  2 (tie)   @LukeMcG  2 (tie)   @tgut03  2 (tie)       Week 2 Results: Congratulations to the Week 2 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 2: Community MembersSolutionsSuper UsersSolutionsPower Automate  @Deenuji  12@ManishSolanki 19 @Anil_g  10 @NathanAlvares24  17 @VishnuReddy1997  6 @Expiscornovus  10 @Tjan  5 @Nived_Nambiar  10 @eetuRobo  3 @SudeepGhatakNZ 8     Week 3 Results: Congratulations to the Week 3 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 3:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji32ManishSolanki55VishnuReddy199724NathanAlvares2444Anil_g22SudeepGhatakNZ40eetuRobo18Nived_Nambiar28Tjan8David_MA22   Week 4 Results: Congratulations to the Week 4 qualifiers, you are being entered in the random drawing that will take place at the end of the challenge. Week 4:Community MembersSolutionsSuper UsersSolutionsPower Automate Deenuji11FLMike31Sayan11ManishSolanki16VishnuReddy199710creativeopinion14Akshansh-Sharma3SudeepGhatakNZ7claudiovc2CFernandes5 misc2Nived_Nambiar5 Usernametwice232rzaneti5 eetuRobo2   Anil_g2   SharonS2  

Check Out | 2024 Release Wave 2 Plans for Microsoft Dynamics 365 and Microsoft Power Platform

On July 16, 2024, we published the 2024 release wave 2 plans for Microsoft Dynamics 365 and Microsoft Power Platform. These plans are a compilation of the new capabilities planned to be released between October 2024 to March 2025. This release introduces a wealth of new features designed to enhance customer understanding and improve overall user experience, showcasing our dedication to driving digital transformation for our customers and partners.    The upcoming wave is centered around utilizing advanced AI and Microsoft Copilot technologies to enhance user productivity and streamline operations across diverse business applications. These enhancements include intelligent automation, AI-powered insights, and immersive user experiences that are designed to break down barriers between data, insights, and individuals. Watch a summary of the release highlights.    Discover the latest features that empower organizations to operate more efficiently and adaptively. From AI-driven sales insights and customer service enhancements to predictive analytics in supply chain management and autonomous financial processes, the new capabilities enable businesses to proactively address challenges and capitalize on opportunities.    

Updates to Transitions in the Power Platform Communities

We're embarking on a journey to enhance your experience by transitioning to a new community platform. Our team has been diligently working to create a fresh community site, leveraging the very Dynamics 365 and Power Platform tools our community advocates for.  We started this journey with transitioning Copilot Studio forums and blogs in June. The move marks the beginning of a new chapter, and we're eager for you to be a part of it. The rest of the Power Platform product sites will be moving over this summer.   Stay tuned for more updates as we get closer to the launch. We can't wait to welcome you to our new community space, designed with you in mind. Let's connect, learn, and grow together.   Here's to new beginnings and endless possibilities!   If you have any questions, observations or concerns throughout this process please go to https://aka.ms/PPCommSupport.   To stay up to date on the latest details of this migration and other important Community updates subscribe to our News and Announcements forums: Copilot Studio, Power Apps, Power Automate, Power Pages

Users online (1,311)