Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
09-28-2021 01:57 AM
I have two json files. I want create a relationship between them. Have a look on my json file:
First Json file:
{
"id": "1234"
}
Second Json File:
{"abstract":
[
{
"value": "<p>chinese</p>",
"language": "chi"
},
{
"value": "<p>eng</p>",
"language": "eng"
}
],
"id":"1234"
}
I need to link two json files based on the id. The problem here is in second json file when I create node there will be two nodes since its an array. so I want link the two node in the second json file to single node on the first json based in the id.
This is code i have used to create node for second json file:
CALL apoc.load.json("file:///D:/secondjson.json") YIELD value as data
FOREACH (abst IN data.abstract | MERGE (abs:Abstract{value:abst.value}) ON CREATE SET abs.language=abst.language
Any hints or suggestions will be great help.
Thank you
Solved! Go to Solution.
09-28-2021 08:05 PM
Thank you very much michael for your approach. It worked for me. But in my case below code worked for me
CALL apoc.load.json("file:///D:/second.json") YIELD value as data
MERGE (a:Paper {id:data.id})
FOREACH (abst IN data.abstract |
MERGE (a)-[:CONTAINS]->(abs:Abstract{value:abst.value})
ON CREATE SET abs.language=abst.language
)
09-28-2021 04:43 PM
I would use this approach:
CALL apoc.load.json("file:///D:/secondjson.json") YIELD value as data
MATCH (n:Paper {id:data.id})
FOREACH (abst IN data.abstract |
MERGE (n)-[:CONTAINS]->(abs:Abstract{value:abst.value})
ON CREATE SET abs.language=abst.language
)
which creates/merges the Abstracts in the context of the main node.
so if there is no abstract yet with that value connected to that Paper node it will create the relationship and the Abstract node
09-28-2021 08:05 PM
Thank you very much michael for your approach. It worked for me. But in my case below code worked for me
CALL apoc.load.json("file:///D:/second.json") YIELD value as data
MERGE (a:Paper {id:data.id})
FOREACH (abst IN data.abstract |
MERGE (a)-[:CONTAINS]->(abs:Abstract{value:abst.value})
ON CREATE SET abs.language=abst.language
)
All the sessions of the conference are now available online