0

I am new to Neo4j and especially with Cypher query. I am trying to create nodes for the values in the JSON file as you can see its in a nested format. Using MERGE because I need the values like 'Adam Smith' as a single node from the nested list below. It clearly works well when 'organization' is not in nested/list format. Please see below of my try out and comments. Really appreciate the help!

Sample data.json

[   {   'organization': 'MIT',
        'student_names': ['Adam Smith'],
        'unique_id': 'ABC123'},
    {   'organization': 'Harvard',
        'student_names': ['Adam Smith', 'Cate Scott'],
        'unique_id': 'ABC124'},
    {   'organization': 'Harvard',
        'student_names': ['Mandy T.', 'Bob Smith'],
        'unique_id': 'ABC125'}]

Creates 2 nodes for organization - works

CALL apoc.load.json('file:///data.json') YIELD value as v 
MERGE (o:org {name: v.organization})
// Added 2 labels, created 2 nodes, set 2 properties, completed after 5 ms.

Doesn't work

CALL apoc.load.json('file:///data.json') YIELD value as v 
UNWIND v.student_names as s
MERGE(st:student {name: s.student_names})

Error: Neo.ClientError.Statement.TypeError: Type mismatch: expected a map but was String("Adam Smith")

Looking for a graph untangled like this. I think I can define the relation on my own, I am just looking to see how to create nodes to begin with.

ABC123 --> MIT --> Adam Smith 
ABC124 --> Harvard --> Adam Smith
ABC124 --> Harvard --> Cate Scott
ABC125 --> Harvard --> Mandy T.
ABC125 --> Harvard --> Bob Smith

1 Answer 1

2

In your second query, s is already the name of a student, so just do this:

CALL apoc.load.json('file:///data.json') YIELD value
UNWIND value.student_names AS s
MERGE(st:student {name: s})
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.