web
You’re offline. This is a read only version of the page.
close
Skip to main content

Notifications

Announcements

Community site session details

Community site session details

Session Id :
Power Automate
Unanswered

Convert Excel to Json

(1) ShareShare
ReportReport
Posted on by 48

Hi, 

 

I have the below table in an excel file and want to convert to json with nested array Properties as shown in the example below. 


How can I achieve this please through an automated flow?

 

Excel Data:

OwnerIDPropertyIDProperty AddressRentBedroom
L001P00112 St LA3002
L001P0023 St SA4503
L002P0034 St SA5004
L003P00420 St LA4002

 

Output Required in Json:

{
    "owner1":{
        "id":"L001",
        "property":[ {
            "propertyID":"P001",
            "Property address":"12 st LA",  
            "Rent":"$300",
            "Bedroom":"2"
        },

        {
            "propertyID":"P002",
            "Property address":"3 st LA",  
            "Rent":"$450",
            "Bedroom":"3"
        }

        ]
    },

 "owner2":{
        "id":"L002",
        "property":[ {
            "propertyID":"P003",
            "Property address":"4 st LA",  
            "Rent":"$500",
            "Bedroom":"4"
        }
    ]
},

"owner3":{
    "id":"L003",
    "property":[ {
        "propertyID":"P004",
        "Property address":"20 st LA",  
            "Rent":"$400",
            "Bedroom":"2"
    }
]

}


}
 
 
Thank You.

 

 

Categories:
I have the same question (0)
  • SudeepGhatakNZ Profile Picture
    14,394 Most Valuable Professional on at
  • garry9318 Profile Picture
    48 on at

    Hi @SudeepGhatakNZ 

     

    I don't think this will help me in that way, I want this in a Microsoft power flow, can you help me in that, please.

  • SudeepGhatakNZ Profile Picture
    14,394 Most Valuable Professional on at

    @garry9318 ,

     

    You can query your Excel file and then use Select action to form a JSON array.

    SudeepGhatakNZ_0-1667864358440.jpeg

     

  • grantjenkins Profile Picture
    11,063 Moderator on at

    This should get you what you want. The only thing you'll need to do is add your additional columns to the Select action.

     

    I've got the following Excel Table for this example:

    grantjenkins_0-1667872479439.png

     

    The full flow is below. I'll go into each of the actions.

    grantjenkins_1-1667872606138.png

     

    List rows present in a table retrieves your Table data.

    grantjenkins_2-1667872650800.png

     

    Select retrieves just the Name and Id properties which we'll use to loop through later.

    grantjenkins_3-1667872701188.png

     

    Compose uses a union expression to remove any duplicate values from Select as we only want one instance of each owner to loop through. The expression here is:

    union(body('Select'),body('Select'))

    grantjenkins_4-1667872793676.png

     

    I then create a string variable called output that will hold the final output once we combine our owners, properties, etc. I set the initial value to {

    grantjenkins_5-1667872855865.png

     

    The Apply to each uses the output from our Compose since we want to loop through each unique owner.

    grantjenkins_6-1667872896131.png

     

    Filter array returns rows that match the current owner's Id using the following expression:

    items('Apply_to_each')?['Id']

    grantjenkins_7-1667872999984.png

     

    Select Properties takes the output from Filter array and allows us to specify exactly what properties we want to include. You'd need to add your additional fields here. We don't include Name and Id here as we already have them outside the objects. The expressions used here are:

    item()?['PropertyID']
    item()?['Address']
    item()?['Number of Bedrooms']

     

    grantjenkins_8-1667873079871.png

     

    Compose Build then concatenates all of our data to build up the JSON array you're after. You should be able to just copy the expression below if you've named all your actions the same as what I have.

    concat('"', items('Apply_to_each')?['Name'], '":{"id":"', items('Apply_to_each')?['Id'], '","property":', body('Select_Properties'), '},')

    grantjenkins_9-1667873245203.png

     

    I then append that output to the output string variable.

    grantjenkins_10-1667873282301.png

     

    Then outside the Apply to each we do the following:

     

    We append a closing } to the output string variable.

    grantjenkins_11-1667873359122.png

     

    And finally, we convert the output to JSON using a json expression.

    json(variables('output'))

    grantjenkins_12-1667873452893.png

     

  • garry9318 Profile Picture
    48 on at

    Hi   @grantjenkins 

    Thanks for your help, I have tried it and it is working, but I am not getting the Json code as required and not even getting the full Code.

     

    Following Excel table:

    Name                     id            PropertyID             Address                        Market rent     No of Bedrooms

    owner11P00112 st LA$3002
    owner11P00214 Louis st LA$5002
    owner22P00315 Merry st LA$5502
    owner22P00429 John st LA$10932

     

    garry9318_1-1667883761760.png

     

    Output got :

    {
      "": {
        "id""2",
        "property": [
          {
            "PropertyID""P003",
            "Address""15 Merry st LA",
            "Market rent""$550",
            "No of Bedrooms ""2"
          },
          {
            "PropertyID""P004",
            "Address""29 John st LA",
            "Market rent""$1093",
            "No of Bedrooms ""2"
          }
        ]
      }
    }
     
    Required Output:
     
    {
        "owner1":{
            "id":"L001",
            "property":[ {
                "propertyID":"P001",
                "Property address":"12 st LA",  
                "Rent":"$300",
                "Bedroom":"2"
            },

            {
                "propertyID":"P002",
                "Property address":"3 st LA",  
                "Rent":"$450",
                "Bedroom":"3"
            }

            ]
        },

     "owner2":{
            "id":"L002",
            "property":[ {
                "propertyID":"P003",
                "Property address":"4 st LA",  
                "Rent":"$500",
                "Bedroom":"4"
            }
        ]
    },

    "owner3":{
        "id":"L003",
        "property":[ {
            "propertyID":"P004",
            "Property address":"20 st LA",  
                "Rent":"$400",
                "Bedroom":"2"
        }
    ]

    }


    }
     
    Can you help me on that please.
  • grantjenkins Profile Picture
    11,063 Moderator on at

    Are you able to send through screenshots of your flow to see what you have put for each of the inputs, etc.?

     

    Below is the output I get:

     

    {
     "owner1": {
     "id": "1",
     "property": [
     {
     "PropertyID": "P001",
     "Address": "12 st LA",
     "No of Bedrooms": "2"
     },
     {
     "PropertyID": "P002",
     "Address": "14 Louis st LA",
     "No of Bedrooms": "2"
     }
     ]
     },
     "owner2": {
     "id": "2",
     "property": [
     {
     "PropertyID": "P003",
     "Address": "15 Merry st LA",
     "No of Bedrooms": "3"
     },
     {
     "PropertyID": "P004",
     "Address": "29 John st LA",
     "No of Bedrooms": "2"
     }
     ]
     },
     "owner3": {
     "id": "3",
     "property": [
     {
     "PropertyID": "P005",
     "Address": "8 Grant st LA",
     "No of Bedrooms": "3"
     }
     ]
     }
    }

     

     

  • garry9318 Profile Picture
    48 on at

    Hi @grantjenkins 

     

    Here's the flow  inputs:

    garry9318_0-1667885019325.png

    garry9318_1-1667885052681.pngunion(body('Select'),body('Select'))

     

     

    garry9318_2-1667885201048.png

    garry9318_3-1667885253505.pngitems('Apply_to_each')?['id']

     

    garry9318_4-1667885449570.png

    item()?['PropertyID']

    item()?['Address']
    item()?['Market rent']
    item()?['No of Bedrooms']
     
    garry9318_5-1667885583246.png
    concat('"', items('Apply_to_each')?['Name'], '":{"id":"', items('Apply_to_each')?['id'], '","property":', body('Select_Properties'), '},')
     

     

    garry9318_7-1667885705434.pngjson(variables('output'))

     

    Thank You.

  • grantjenkins Profile Picture
    11,063 Moderator on at

    In your first Select can you change the Header from Id to id (lowercase i) to see if that fixes it.

  • grantjenkins Profile Picture
    11,063 Moderator on at

    I don't think that's the issue actually.

     

    It seems as though your Name value isn't coming through. Can you run the flow again and have a look at the output from your List rows present in a table, and the following Select. I wonder if your Name column in Excel is coming through with a different header (maybe not called Name).

  • grantjenkins Profile Picture
    11,063 Moderator on at

    Also, can you check that the input into your Apply to each is using the output from the Compose and not the Select.

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

Forum hierarchy changes are complete!

In our never-ending quest to improve we are simplifying the forum hierarchy…

Ajay Kumar Gannamaneni – Community Spotlight

We are honored to recognize Ajay Kumar Gannamaneni as our Community Spotlight for December…

Leaderboard > Power Automate

#1
Michael E. Gernaey Profile Picture

Michael E. Gernaey 522 Super User 2025 Season 2

#2
Tomac Profile Picture

Tomac 364 Moderator

#3
abm abm Profile Picture

abm abm 243 Most Valuable Professional

Last 30 days Overall leaderboard