Question: I have the following json file (data.json):

```
{
    "data": [
        {"name": "Folder One", "type": "folder", "id": 1},
        {"name": "Folder Two", "type": "folder", "id": 2},
        {"name": "File One", "type": "file", "id": 1, "folder_id": 1},
        {"name": "File Two", "type": "file", "id": 2, "folder_id": 2}
    ]
}

```

I want to import and create two labels (`:Folder` and `:File`) and a relationship `[:BELONGS_TO]`.

Getting stuck here:

```
CALL apoc.load.json("file:/data.json") YIELD value
with value['data'] as data
UNWIND data as row

...
(
    foreach where type is "folder" create a :Folder
    foreach where type is "file" create a :File and a relationship [:BELONGS_TO] to folder
)

```

How would you do this?

Answer: 
You need to hardcode the Labels matching in FOREACH.

**First, create an index on id property of File and Folder:**

```
CREATE INDEX ON :File(id)
CREATE INDEX ON :Folder(id)

```

**Then create nodes or relationships:**

```
CALL apoc.load.json("file:/data.json") YIELD value
with value['data'] as data
UNWIND data as row
FOREACH (ignoreMe in CASE WHEN row.type="folder" THEN [1] ELSE [] END | 
    MERGE (f:Folder{id: row.id}) 
    SET f.name= row.name)
FOREACH (ignoreMe in CASE WHEN row.type="file" THEN [1] ELSE [] END | 
    MERGE (folder:Folder{id: row.folder_id}) 
    MERGE (file:File{id: row.id}) 
    ON CREATE SET 
        file.name= row.name  
    MERGE (file)-[:BELONGS_TO]->(folder))

```
We usually discourage using a single import file for creating nodes of multiple unrelated types, but for these cases there are a couple different approaches:

1. Use multiple passes through the file, one per type, filtering the rows per type so you only process nodes of one type in the query, using CREATE or MERGE on the hardcoded label (and making sure you have an index present if using MERGE).
2. Use a common type for all nodes imported (something like :Node if it's very generic, or a more general type that fits all types to be imported in the file) such that all nodes you CREATE or MERGE (and again ensure you have an index present associated with the more generic label if using MERGE) use that generic label, and after the node is created use [APOC Procedures](https://neo4j-contrib.github.io/neo4j-apoc-procedures/) to dynamically set the remaining label(s) with [apoc.create.addLabels()](https://neo4j-contrib.github.io/neo4j-apoc-procedures/#data-creation).

Since your structure is about creating folders and files and the relationship between them, I'd recommend the first approach, first creating all :Folder nodes, then the second creating the :File nodes performing the match to your previously-imported :Folder nodes and creating the relationship.