I have a has_many nested relation that I'm trying to match with a json result.
The following blog example shows what I want to do, except for it not nested
MATCH (a:Person { name: "Andres" })-[:FATHER_OF]->(child) RETURN {name:a.name, kids:collect(child.name)} as document
Instead, I want something like this
MATCH (a:Person { name: "Andres" })-[:FATHER_OF]->(child)-[:has_read]->(book)-[:has_chapter]->(chapter) RETURN {name:a.name, kids:collect({"name":child.name, has_read:collect(book)})} as document
In this case, I would like to return a json object of such a structure:
{ "name": "Andres" "kids": [ { "name":"Bob" "has_read": [ { "name":"Lord of the Rings", "chapters": ["chapter1","chapter2","chapter3"] }, { "name":"The Hobbit", "chapters": ["An unexpected party","Roast mutton"] } ] }, { "name":"George" "has_read": [ { "name":"Lord of the Rings", "chapters": ["chapter1","chapter2","chapter3"] }, { "name":"Silmarillion", "chapters": ["chapter1","chapter2"] } ] } ] }
source share