skip to Main Content

Neo4j Desktop:
There is a big JSON file with entries like the one shown below.
I want to split up the entries of "src" and create nodes with each single one of the entries.
Further i want the other values to be the nodes parameters.
Input via JSON file (see below).

What is the best way to do all this stuff?

{
    "transaction":  "42043-134632465-3221",
    "action":  "Accept",
    "src":  "dummy593, dummy834, dummy203",
    "adds":     {
                },
    "dest":     {
                    "name":  "John Doe",
                    "address":  "Baker Street",
                    "phone":  "12345, 54321"                  
                }
}

I tried to combine the functions of apoc.load.json, apoc.cyper.run and within this i used split(src, ‘,’).
I’ve gotten a security error and honestly i don’t think it would’ve worked though.
Should i use apoc.load.json or something like with{json}?

call apoc.load.json("file:/Users/user/.Neo4jDesktop/relate-data/dbmss/dbms-969/import/example.json") YIELD value
with value.src as src
call apoc.cypher.run("with $src as src unwind src as src create (:src {src: src})", {src: split(src, ',')}) yield value
return value

Apologies and thanks – i’m bloody new in cypher topics …

2

Answers


  1. You can do something like this:

    call apoc.load.json("file:/var/lib/neo4j/import/so.json") YIELD value
    with value.src as tsrc
    unwind(split(tsrc,',')) as tempsrc
    create (s:Source {src:tempsrc})
    
    Login or Signup to reply.
  2. This is using foreach command which is similar to unwind.

    call apoc.load.json("example.json") YIELD value
    with split(value.src,',') as srcs
    foreach (src in srcs | create (:src {src: src}))
    

    Reference:
    https://neo4j.com/docs/cypher-manual/current/clauses/foreach/

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search