How to parse graph link json in python

I want to build a button based chatbot for that i have created a graph link json using networkx. But i am not able to parse it. I want the json format to be in nested format like parent and child. But that is not giving me attributes. Please help me. I used the below code to get the below response.

import json
import
import networkx as nx
from networkx.readwrite import json_graph    
DG.add_node(1)
DG.add_node(2)
DG.add_edges_from([(1,3, {'button': 'yes'}),(3,4, {'button': 'no'})])
DG.add_edges_from([(4,5,{'button': 'yes'}),(4,6)])
DG.add_edge(1,2)
data = json.dumps(json_graph.node_link_data(DG))

Response:

{"directed": true, "multigraph": false, "graph": {}, "nodes": [{"id": 1}, {"id": 2}, {"id": 3}, {"id": 4}, {"id": 5}, {"id": 6}], "links": [{"button": "yes", "source": 1, "target": 3}, {"source": 1, "target": 2}, {"button": "no", "source": 3, "target": 4}, {"button": "yes", "source": 4, "target": 5}, {"source": 4, "target": 6}]}

I tried getting tree like json response but it is not having the attribute values.

Code:

json_graph.tree_data(DG,root=1)

Response:

{'id': 1, 'children': [{'id': 3, 'children': [{'id': 4, 'children': [{'id': 5}, {'id': 6}]}]}, {'id': 2}]}

I know this is not directly related to RASA but i need a way to do that.

yes, this question is not related to rasa, I recommend to try to find an answer on other resources

@Ghostvv sure. Thanks for your response :slight_smile: