title: Neo4j How to Create Multiple Lists From Values in Nested JSON
body: <p>I have this JSON Data:</p>
  
  <pre><code>{"title": "Title1", "authors": [{"name": "Dave Chappelle", "org": "MIT"}], "id": "abc123"}
  {"title": "Title2", "authors": [{"name": "Rick Sanchez"}, {"name": "Amy Schumer"], "id": "xyz234"}
  </code></pre>
  
  <p>And I want to create some information that looks like:</p>
  
  <p><code>[“author1”, “author2",... “authorN”]</code> for every paper in the JSON file.</p>
  
  <p>For example, with the first line of data, the list would just be <code>["Dave Chappelle"]</code> </p>
  
  <p>The second line of data the list would be <code>["Rick Sanchez, "Amy Schumer"]</code> </p>
  
  <p>Once I have this, I want to do some Cypher operations using each of these lists. Specifically, I want to create a relationship between each author in a paper and a paper, with the <code>AUTHORED</code> relationship having two properties, <code>is_first_author</code> and <code>is_last_author</code> with boolean values. </p>
  
  <p>For a single piece of data in the JSON file, I know the following works to identify elements in a given list and gives a boolean value for if each element is the first or last:</p>
  
  <pre><code>WITH [“author1”, “author2", “author3”, “author4"] AS authors
  UNWIND range(0,size(authors)-1,1) as idx
  return idx, authors[idx], idx=1 AS is_first_author, idx=size(authors)-1 as is_last_author
  </code></pre>
  
  <p>and returns </p>
  
  <pre><code>idx authors[idx]    is_first_author is_last_author
  0   "author1"   false   false
  1   "author2"   true    false
  2   "author3"   false   false
  3   "author4"   false   true
  </code></pre>
  
  <p>In order get this list of authors and add these properties to the relationship between each author and their paper, I'm using the following code:</p>
  
  <pre><code>CALL apoc.load.json('file.txt') YIELD value AS q UNWIND q.id AS id UNWIND q.authors as authors
  MERGE (i:Quanta {id:q.id}) 
  MERGE (a:Author {name:authors.name})
  FOREACH (quanta IN q.id | WITH quanta.authors as authors 
  WITH collect(authors.name) as names 
  UNWIND range(0,size(names)-1,1) as idx 
  MERGE (a)-[:AUTHORED {is_first_author:idx=1}, {is_last_author: idx=size(authors)-1}]-(i)
              RETURN *;
  </code></pre>
  
  <p>However, this gives me a syntax error:</p>
  
  <pre><code>Invalid input ',': expected whitespace or ']' (line 4, column 177 (offset: 380))
  "FOREACH (quanta IN q.id | WITH quanta.authors as authors WITH collect(authors.name) as names UNWIND range(0,size(names)-1,1) as idx MERGE (a)-[:AUTHORED {is_first_author:idx=1}, {is_last_author: idx=size(authors)-1}]-(i)"
  </code></pre>
  
  <p>I am also fairly certain that using a <code>WITH</code> statement inside of the <code>FOREACH</code> is not syntactically valid, but I'm not quite sure how to do this otherwise. </p>
  
  <p>Any suggestions would be greatly appreciated!</p>