cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Anonymous
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

2 REPLIES 2
abm
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.

 

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

 

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 blog
Power Automate Video Tutorials
Anonymous
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.


Thanks,
Best Regards

Helpful resources

Announcements
Power Platform Conf 2022 768x460.jpg

Join us for Microsoft Power Platform Conference

The first Microsoft-sponsored Power Platform Conference is coming in September. 100+ speakers, 150+ sessions, and what's new and next for Power Platform.

May UG Leader Call Carousel 768x460.png

June User Group Leader Call

Join us on June 28 for our monthly User Group leader call!

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.

Power Automate Designer Feedback_carousel.jpg

Help make Flow Design easier

Are you new to designing flows? What is your biggest struggle with Power Automate Designer? Help us make it more user friendly!

Top Solution Authors
Top Kudoed Authors
Users online (1,479)