Create Nested Hierarchy Response from Cypher Query Response (Nodes/Relationships)

I am struggling to find the best way to translate the response from Neo 4 J's cypher nodes/relationships payload into something more readable. I was thinking a nested hierarchy was a great way to use my graph in code but I am not sure the best way to go about it. Nested hierarchy response is really just a json payload where I can see the levels of my hierarchy. All the higher level nodes will show their children and then those children will also have children, etc. A hierarchy view would be nice for my applications to read and use.

I have attached an input image and and output image. I was trying to attach files but I could not.

input_cypher_response.png

input_cypher_response_2.png

output_hiearchy_response.png

In my opinion, cypher is not the tool to do this, as it is not a scripting language with flow control. Cypher queries really run start-to-finish. This would be very easy to do with a custom procedure, as you would be able to write a simple recursive algorithm that would traverse the graph and accumlate the data exactly as you want it.

If you are using a driver to query the database, you could write an algorithm to take the paths returned from a cypher query and convert them into the format you want. This would not be too hard, as all the paths start from the same node. The children of that node are the distinct list of nodes at the second position along each path. The children of each of those nodes are the ones at the third position along each path. You just need to group them with their parent node. You can get this information from the relationships along the path, as each relationship identifies its starting and ending nodes, thus you can get the other node attached to a given node.

Thanks for the response. So that is exactly what I am asking, are there a set of helper functions/algorithms that will help me do this. I have written a recursive function for this and it seems to work but after testing on other inputs I think I am missing something. Before I dove deeper into this definition I thought I would ask the community if there is a helper library or set of common functions that translate the cypher query response into something a bit more useful. I know the cypher language is powerful but using the response that is given makes it slightly hard to interpret and and use in another application. I know we can see the graph in Neo 4 J browser but if I would like to use that graph in my application I need to have a way to better to translate the response into something a bit more readable. Really appreciate the response @glilienfield and what I am asking might not be the job of Neo 4 J but I thought I would just ask haha.

Do you have access to your server to deploy a custom procedure plugin? It requires Java development, but the procedure would not be hard.

I did look into custom procedure plugins, but I think I can just stick to the language I am retrieving the cypher response in. Thanks!