cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Ali_Nawaz
Helper III
Helper III

Hierarchical jSon in flow

Hi PowerUsers,

I want to create a hierarchical JSon in Flow which should hold a parent child format in it. 
I am fetching the source data from SQL which needs to be transformed into this Json format, then this JSon will be passed to an Organogram which is being created on javascript.
Here is a sample of what i am trying to achieve.

{
     'name': 'Lao Lao',
     'title': 'general manager',
     'children': [
       { 'name': 'Bo Miao', 'title': 'department manager' },
       { 'name': 'Su Miao', 'title': 'department manager',
         'children': [
           { 'name': 'Tie Hua', 'title': 'senior engineer' },
           { 'name': 'Hei Hei', 'title': 'senior engineer',
             'children': [
               { 'name': 'Pang Pang', 'title': 'engineer' },
               { 'name': 'Xiang Xiang', 'title': 'UE engineer' }
             ]
            }
          ]
        },
        { 'name': 'Hong Miao', 'title': 'department manager' },
        { 'name': 'Chun Miao', 'title': 'department manager' }
      ]
}


In SQL, I have Employee ID and ParentPositionID in the same table which specifies who reports to whom.

The challenge is to transform the SQL data into this JSon format to "Nth" level.

I do not know how many levels of hierarchy could be there.
I need to create a recursion in flow which goes to the "Nth" level of hierarchy and on the same time the load/computation time of this flow should be as less as possible because this JSon will be associated with a Javascript which will be displaying the data retrieved form JSon on runtime.


I have tried nested looping but it takes too much of time for calculating even 10 employees data.
I am looking for a fast and accurate solution for this problem.

What can be the best possible solution for this ?
I'm looking forward to usual helpful responses.


Best Regards,
Ali Nawaz

2 REPLIES 2
abm
Super User
Super User

Hi @Ali_Nawaz

 

Very interesting question you posted and a challenging one.

 

PowerAutomate connectors can get the results (Collection), then iterate the loop or some situation we can use Select action step to filter the contents. My view is you probably could build this in flow but might have performance issues. 

 

Did you thought about generating this JSON from SQL itself?  Not sure how fast that will be.

 

https://docs.microsoft.com/en-us/sql/relational-databases/json/format-query-results-as-json-with-for...

 

Thanks

 

 



Did I answer your question? Mark my post as a solution!

If you liked my response, please consider giving it a thumbs up


Proud to be a Flownaut!

Learn more from my blogPower Automate Video Tutorials

Hi @abm yes i saw the json converter function of SQL but it doesn't suffice the need.
It doesn't create the nested json which we are looking for.

I am looking for an approach which is time efficient and gives nested json.
I do not mind going outside the domain of Flow/SQL/PowerApps, just looking for a good workaround for this challenge.


Thanks,
Best Regards

Helpful resources

Announcements
MPA_User Group Leader_768x460.jpg

Manage your user group events

Check out the News & Announcements to learn more.

Community Connections 768x460.jpg

Community & How To Videos

Check out the new Power Platform Community Connections gallery!

Welcome Super Users.jpg

Super User Season 2

Congratulations, the new Super User Season 2 for 2021 has started!

Carousel 2021 Release Wave 2 Plan 768x460.jpg

2021 Release Wave 2 Plan

Power Platform release plan for the 2021 release wave 2 describes all new features releasing from October 2021 through March 2022.

Top Solution Authors
Users online (1,407)