Showing results for 
Search instead for 
Did you mean: 
Not applicable

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

Super User
Super User

Hi @Anonymous


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.





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 blog
Power Automate Video Tutorials
Not applicable

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.

Best Regards

Helpful resources

MPA Virtual Workshop Carousel 768x460.png

Register for a Free Workshop

Learn to digitize and optimize business processes and connect all your applications to share data in real time.

Microsoft Build 768x460.png

Microsoft Build is May 24-26. Have you registered yet?

Come together to explore latest innovations in code and application development—and gain insights from experts from around the world.

May UG Leader Call Carousel 768x460.png

What difference can a User Group make for you?

At the monthly call, connect with other leaders and find out how community makes your experience even better.

PA Survey Carousel Image.png

We want to hear from you!

If you are a small business ISV/Reseller, share your thoughts with our research team.

Users online (1,269)