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.

Create nodes from multiple .json files in one .cypher script

I am new to neo4j cypher.
I have a few .json files that I copy to my DBMS's folder using python.

Once the .json files are in the folder, I'd like to create a node for each of the dictionaries inside of the json list files.

The cypher query shown belows does, quite frankly, nothing.

 

CALL apoc.load.json('processes.json') YIELD value AS  processes UNWIND processes AS Process
CALL apoc.load.json('files.json') YIELD value AS  files UNWIND files AS File
CALL apoc.load.json('registry.json') YIELD value AS  registries UNWIND registries AS Registry
CREATE(f:File)
CREATE(p:Process)
CREATE(r:Registry)
RETURN Registry

An example for 'processes.json'
[
{
    "Image": "C:\\Windows\\System32\\LogonUI.exe",
    "ProcessGuid": "CF649360-314A-637D-6901-000000000800",
    "ProcessId": 1040, "RuleName": "-", "User": "NT AUTHORITY\\SYSTEM",
    "UtcTime": "2022-11-22 20:30:06.003", "Description": "Process was created."
}
]

I think my problems are understanding how to create a node from a .json that way, and creating multiple nodes in the same cypher query.
Appriciate any help!
3 REPLIES 3

dana_canzano
Neo4j
Neo4j

@oy7031 

even if this did work your reference to

 

CREATE(f:File)
CREATE(p:Process)
CREATE(r:Registry)

 

 is simply going to create 3 nodes with no properties, and thus a node with label :File a node with label :Process and a node with label :Registry.    .... and I suspect this is not what you want.

Maybe you want something similar to 

 

CALL apoc.load.json('processes.json') YIELD value AS  processes UNWIND processes AS Process
CREATE(p:Process) set p.image=Process.Image,
                      p.processguid=Process.ProcessGuid,
                      p.processid=Process.processid
                      p.utctime=Process.UtcTime;

CALL apoc.load.json('files.json') YIELD value AS  files UNWIND files AS File
CREATE(f:File) set f........
CALL apoc.load.json('registry.json') YIELD value AS  registries UNWIND registries AS Registry
CREATE(r:Registry) set r........

 

note the references above and on line 8 and 10 and to set f........ and set r........ would need to be further defined by you

 

Is there no way to load all fields from the dictionary in a generic way? Seems like a pretty common use case to me..

dana_canzano
Neo4j
Neo4j

@oy7031 

yes https://neo4j.com/docs/cypher-manual/current/clauses/create/#create-create-multiple-nodes-with-a-par... . 

 

try

 

 

CALL apoc.load.json('processes.json') YIELD value AS  processes UNWIND processes AS Process
CREATE(p:Process) set p=Process