Cypher Return formatted json response

I'm new to neo4j and cypher and am having trouble with grouping queries with 'WITH' and 'Collect', so i have this graph as shown in the image below :


The normal response that i get has many repeated values , so i want a json result that's formatted like the following:

processes:[
     {
      node,
      subprocesses:[
                    {node , events: [
                                     {node}
                                    ] 
                    },
                    { //
                    }
                   ]
     },
     {
      node,
      subprocesses:[
                    {node , events: [
                                     {node}
                                    ] 
                    },
                    { //
                    }
                   ]
     }
]

Is there a way to regroup the graph like this on cypher or not ? Thank in advance!! :smile:

Can you please, post the query you have used so far ?

Although you can build the query to match your response, you will have to build the response in the required JSON format yourself.
Not sure of how many embedded levels you can have in your JSON: one or more than one?

I'm having a hard time following what you want but I will suggest maybe the DISTINCT function could help.