# How to create a flow dynamically given a tree structure

**URL:** <https://discourse.nodered.org/t/how-to-create-a-flow-dynamically-given-a-tree-structure/81541>\
**Category:** General\
**Created:** [24 September 2023 13:20 UTC](https://discourse.nodered.org/t/how-to-create-a-flow-dynamically-given-a-tree-structure/81541 "2023-09-24T13:20:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Gio-Formichella](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/gio-formichella/32/83175_2.png) [@Gio-Formichella](https://discourse.nodered.org/u/Gio-Formichella)\
**Post date:** [24 September 2023 13:20 UTC](https://discourse.nodered.org/t/how-to-create-a-flow-dynamically-given-a-tree-structure/81541/1 "2023-09-24T13:20:59Z")

</div>

I have a Java web application with tree data structures in XML, by pressing a button I want it to open the Node-RED editor page and have it display a flow containing function nodes with the same "structure" of the chosen tree and predetermined JavaScript code inside. To give and example, if I have select a tree with just a root node and 2 children and press the "export to Node-RED" button I would like the result to be the following:

 ![Immagine 2023-09-24 103031](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/2/4/24a964ec13639b061f3dc0e87f245afcc752aa79.png)

Is there an API that can help me with this ? Is there a way to generate the JSON flow before opening up the editor ?

---

<div class="post-metadata">

**Author:** ![E1cid](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/e1cid/32/77971_2.png) [@E1cid](https://discourse.nodered.org/u/E1cid)\
**Post date:** [24 September 2023 14:06 UTC](https://discourse.nodered.org/t/how-to-create-a-flow-dynamically-given-a-tree-structure/81541/2 "2023-09-24T14:06:13Z")

</div>

Hi and welcome to the forum.

At the top of this page is a link to the [documentation](https://nodered.org/docs/), on that page you would find a link to to [API references](https://nodered.org/docs/api/), on that page is a link to [Admin http API](https://nodered.org/docs/api/admin/).

You will have to write some code to generate your flow.json of course. Or if you structure your xml you may be able to pass it through the xml node, then a json node to generate a JSON. You could set up a http endpoint flow to possibly do this for you.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [23 November 2023 14:06 UTC](https://discourse.nodered.org/t/how-to-create-a-flow-dynamically-given-a-tree-structure/81541/3 "2023-11-23T14:06:28Z")

</div>

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.
