Skip to main content

Notifications

Community site session details
Power Automate - Power Automate Desktop
Answered

Data Table to JSON object in PAD

Like (1) ShareShare
ReportReport
Posted on 25 Oct 2021 12:50:55 by 10

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.

  • Suggested answer
    CU15100424-0 Profile Picture
    2 on 15 Oct 2024 at 04:32:59
    Data Table to JSON object in PAD
    Thank you for the solution, but the issue I'm trying to resolve is that instead of searching for %CSV[1]%, I would like to search using %CSV.Company%. After some experimentation, I found that converting the DataTable to JSON, renaming it, and then converting it back helped solve my problem. Here’s the code in case anyone else finds it useful.
    File.ReadFromCSVFile.ReadCSV CSVFile: $'''C:\\Users\\Stanleyco93\\Downloads\\Test.csv''' Encoding: File.CSVEncoding.UTF8 TrimFields: True FirstLineContainsColumnNames: False ColumnsSeparator: File.CSVColumnsSeparator.SystemDefault CSVTable=> CSVTable
    LOOP FOREACH CurrentItem IN CSVTable[0]
        Variables.AddItemToList Item: CurrentItem List: Field
    END
    Variables.DeleteRowFromDataTable DataTable: CSVTable RowIndex: 0
    SET JSON TO {{ }}
    SET JSON['CSVTable'] TO CSVTable
    Variables.ConvertCustomObjectToJson CustomObject: JSON Json=> JSON
    SET LoopIndex TO 0
    LOOP FOREACH CurrentItem IN Field
        Text.Replace Text: JSON TextToFind: $'''Column#%LoopIndex + 1%''' IsRegEx: False IgnoreCase: False ReplaceWith: CurrentItem ActivateEscapeSequences: False Result=> JSON
        Variables.IncreaseVariable Value: LoopIndex IncrementValue: 1
    END
    Variables.ConvertJsonToCustomObject Json: JSON CustomObject=> JsonAsCustomObject
    
     
  • HassenH Profile Picture
    2 on 24 Jan 2024 at 15:10:52
    Re: Data Table to JSON object in PAD

    Thanks for this mate really helpfull but i have a issue one my side. 

     

    Here are the steps as you mentionned them. 

    StepsSteps

    This is the data in my table before converting to JSON. 

    Table before converting to JsonTable before converting to Json

    And that's the output in my JSON. 

    Json DataJson Data

     

    Any ideas ? 

     

    Thanks y'all 

  • cjaldrich74 Profile Picture
    8 on 24 Dec 2023 at 23:45:21
    Re: Data Table to JSON object in PAD

    I appreciate your response. It sent me in a different direction, and I ended up using SQL to import the data from Excel. It not only allowed me to accomplish exactly what I was trying to do, but it also saved time in the flow by eliminating all of the steps to open Excel, read from and close. It also kept me from having to add more loops.

  • Agnius Bartninkas Profile Picture
    10,045 Most Valuable Professional on 24 Dec 2023 at 05:44:17
    Re: Data Table to JSON object in PAD

    You don't need to convert your table to JSON. You can use Find and replace in data table to find the rows you want, and then build a loop to insert them one by one to your new data table.

     

    I would recommend creating a separate topic for this, though.

  • cjaldrich74 Profile Picture
    8 on 24 Dec 2023 at 05:42:26
    Re: Data Table to JSON object in PAD

    I'm not sure this is possible, but I have a datatable created from the action Read From Excel. It has 6 columns and 60 rows. I would like to create a new datatable that contains only the rows that match another variable. The purpose would be to use the new datatable in a For Each Loop so that it doesn't waste time iterating through all of the datarows for only a few matches. It ends up making the flow unnecessarily time consuming.

     

    So I went through the steps to convert the datatable to JSON. Now, what can I do to filter only the matches? I have tried scripting using Python and JS, but I am getting errors. 

    If I manage to figure that step out, would I be able to use Python to return the JSON as a datatable? Maybe I need to just split the Excel table into several smaller ones for each match I am trying to loop through?

     

    I am learning as I go, and it would sure be nice to make this happen efficiently in PAD!

  • Mithlesh Profile Picture
    17 on 27 Feb 2023 at 04:05:43
    Re: Data Table to JSON object in PAD

    Hi @Agnius , Thank you so much to resolve the issue. 

     

    -- Below is comment for the readers

    When you set a variable to custom object , In the new value type %{{ }}%. I was missing these % and varibale was not set to custom object.

     

    Thanks,

    Mithlesh

  • Agnius Bartninkas Profile Picture
    10,045 Most Valuable Professional on 24 Feb 2023 at 11:01:36
    Re: Data Table to JSON object in PAD

    You're doing it wrong. You need to use %NewVar['Table']% in the Variable field and not the Value field:

    AgniusBartninka_0-1677236483872.png

     

  • Mithlesh Profile Picture
    17 on 23 Feb 2023 at 14:29:25
    Re: Data Table to JSON object in PAD

    Hi @Agnius ,

     

    I have added %NewVar['Table']% to 3rd step but it give me the Error:  Variable 'NewVar' does not have a property 'Table'. I even tried setting to %NewVar['NewInput']% but i am getting the same error.  Can you please advise

     

    Mithlesh_0-1677162287565.png

     

    Mithlesh_1-1677162316248.png

     

    Mithlesh_2-1677162436171.png

     

    TIA

    Mithlesh

  • Mithlesh Profile Picture
    17 on 23 Feb 2023 at 14:29:19
    Re: Data Table to JSON object in PAD

    Hi @Agnius ,

     

    I have added %NewVar['Table']% to 3rd step but it give me the Error:  Variable 'NewVar' does not have a property 'Table'. I even tried setting to %NewVar['NewInput']% but i am getting the same error.  Can you please advise

     

    Mithlesh_0-1677162287565.png

     

    Mithlesh_1-1677162316248.png

     

    Mithlesh_2-1677162436171.png

     

    TIA

    Mithlesh

  • Agnius Bartninkas Profile Picture
    10,045 Most Valuable Professional on 23 Feb 2023 at 04:23:08
    Re: Data Table to JSON object in PAD

    Hello. What you are doing there is overwriting the custom object with a table. This means that you create a custom object, but then turn it into a data table variable by overwriting it, and it is thus no longer a custom object by the time you try to convert it. Instead, you should assign the data table to a property inside the custom object and not the entire object.

     

    In your step #3, instead of setting it to %NewVar%, try setting it to %NewVar['Table']%. This will add a property called 'Table' to your custom object with the data of %NewInput% inside. This way your custom object will remain as custom object that stores a table inside of it.

Under review

Thank you for your reply! To ensure a great experience for everyone, your content is awaiting approval by our Community Managers. Please check back later.

Helpful resources

Quick Links

Understanding Microsoft Agents - Introductory Session

Confused about how agents work across the Microsoft ecosystem? Register today!

Warren Belz – Community Spotlight

We are honored to recognize Warren Belz as our May 2025 Community…

Congratulations to the April Top 10 Community Stars!

Thanks for all your good work in the Community!

Leaderboard > Power Automate - Power Automate Desktop

#1
eetuRobo Profile Picture

eetuRobo 18 Super User 2025 Season 1

#2
stampcoin Profile Picture

stampcoin 6

#2
John_Mavridis Profile Picture

John_Mavridis 6 Microsoft Employee

Overall leaderboard