Please could someone help me. I figured out a lot but.. I am stuck..
I am trying to import JSON into my graph using the apoc.json.load mechanism.
i made a simple JSON packet which shows the structure and I am sending a small code segment for you to look at and run. In the code segment I placed my question, hopefully you can help me.
The JSON Packet:
{
"familyName":"happyFolks",
"dad": "Pete",
"mom":"Sue",
"children":[
{
"name":"Paul",
"hobbies":
},
{
"name":"Pete",
"hobbies": [
{
"sport":{"type":"baseball", "wins":10, "loses":3},
"colors":[ 32, 32, 255 ]
},
{
"sport":{"type":"football", "wins":5, "loses":3},
"colors":[ 20, 32, 124 ]
}
]
}
]
}
My Apoc Code:
CALL apoc.load.json("family.json") YIELD value
merge (fam:Family{Name:value.familyName })
merge (dad:Dad{Name:value.dad})
merge (fam)-[:goesTo]->(dad)
merge (mom:Mom{Name:value.mom})
merge (fam)-[:goesTo]->(mom)
merge (childrenRoot: Children{Name:"Children"})
merge (fam)-[:goesTo]->(childrenRoot)
With value, fam, childrenRoot
UNWIND value.children AS children
merge (child:Child{Name: children.name})
merge (childrenRoot)-[:goesTo]->(child)
// how do I handle hobbies?
// create a sport node off of each child and then I would like a baseball node and a football node off of the child’s sport node with their associated elements
With value
Match (nodes) return count(nodes)
The Graph I Generate:
How do I add in the Hobby elements? everything I try fails. what is the trick?
thanks guys! thanks man for helping me out on this..