Search code examples
neo4jcypherpy2neogqlneo4j-apoc

How to parse json and create nodes with foreach in Neo4j?


Sample json:

{
    "data": [
            {
                "file" : "1.txt",
                "type" : "text"
            },
            {
                "file" : "2.json",
                "type" : "json"
            },
            {
                "file" : "1.html",
                "type" : "html"
            }
    ]
}

I am trying to create 3 nodes with file and type as properties

I am using following query to create nodes in neo4j

WITH {json} AS document 
UNWIND document.data AS data
FOREACH (node in data| CREATE(m:`member`) SET m = node )

I am getting following error when i use py2neo driver:

AttributeError: 'module' object has no attribute 'SyntaxError'


Solution

  • Query should be like -

     WITH {json} AS document
     FOREACH (node in document.data| CREATE(m:`memeber`) SET m = node )