krishna reddy
krishna reddy

Reputation: 325

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'

Upvotes: 0

Views: 1335

Answers (2)

Michael Hunger
Michael Hunger

Reputation: 41706

In your case either use UNWIND or FOREACH

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

or

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

Upvotes: 1

krishna reddy
krishna reddy

Reputation: 325

Query should be like -

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

Upvotes: 0

Related Questions