title: Nested has_many relationships in cypher
body: <p>I have a nested has_many relationship that I'm trying to map to a json result.</p>
  
  <p>The following example from the blog shows the kind of thing I want to do, except it's not nested</p>
  
  <pre><code> MATCH (a:Person { name: "Andres" })-[:FATHER_OF]-&gt;(child)
    RETURN 
    {name:a.name, kids:collect(child.name)} as document
  </code></pre>
  
  <p>What I want instead is something like this</p>
  
  <pre><code> MATCH (a:Person { name: "Andres" })-[:FATHER_OF]-&gt;(child)-[:has_read]-&gt;(book)-[:has_chapter]-&gt;(chapter)
    RETURN 
    {name:a.name, kids:collect({"name":child.name, has_read:collect(book)})} as document
  </code></pre>
  
  <p>In this case I would like to return a json object of a structure like this:</p>
  
  <pre><code>{
    "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"]
                             }
                           ]
             }
  
            ]
  }
  </code></pre>