How to create relation from two json files and link them?

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

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

1 Like

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
)