cancel
Showing results for 
Search instead for 
Did you mean: 

Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.

Possible to use read json files from a folder and run same cypher import json script on all files?

kasipasi
Node Clone

I have multiple json files in a folder. Possible to read whole folder and import all or do I have to specify file by file?`

kasipasi_1-1664962389237.png

 

1 ACCEPTED SOLUTION

Looks like you can do this using APOC procedure to give a list of files in a folder or all sub folders.  The documentation has an example of what you want to do. 

https://neo4j.com/labs/apoc/4.4/overview/apoc.load/apoc.load.directory/

View solution in original post

2 REPLIES 2

Looks like you can do this using APOC procedure to give a list of files in a folder or all sub folders.  The documentation has an example of what you want to do. 

https://neo4j.com/labs/apoc/4.4/overview/apoc.load/apoc.load.directory/

For who need some help on this:

Here is an example code that worked for me using apoc.load.directory and after apoc.load.json to read data every all json files.

 

CALL apoc.load.directory("*.json", "json")
YIELD value as files
UNWIND files as file
CALL apoc.periodic.iterate('
    CALL apoc.load.json($file)
    YIELD value as line
', '
   //UNWIND $listOfMaps AS properties
    //CREATE (n: Product2) SET n = properties
    CREATE (pc:Product2{catalogPathID: line.catalogPathID}) //Process line here
', {batchSize:10000, parallel:true, params: {file: file}})
YIELD batches, total, updateStatistics
RETURN batches, total, updateStatistics