# How to form a graph DB from relation object

**URL:** <https://community.neo4j.com/t/how-to-form-a-graph-db-from-relation-object/58779>\
**Category:** Neo4j Graph Platform\
**Tags:** migrated, python-tagged\
**Created:** [December 20, 2022, 6:56am UTC](https://community.neo4j.com/t/how-to-form-a-graph-db-from-relation-object/58779 "2022-12-20T06:56:25Z")\
**Posts on this page:** 5\
**Page:** 2

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [December 26, 2022, 12:40pm UTC](https://community.neo4j.com/t/how-to-form-a-graph-db-from-relation-object/58779/21 "2022-12-26T12:40:17Z")

</div>

Is this a main node for each json imported, if so, how will you differentiate each main node? Will you use a unique ‘id’ or ‘name’ property?

---

<div class="post-metadata">

**Author:** ![Jupyter123](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@Jupyter123](https://community.neo4j.com/u/Jupyter123)\
**Post date:** [December 26, 2022, 12:44pm UTC](https://community.neo4j.com/t/how-to-form-a-graph-db-from-relation-object/58779/22 "2022-12-26T12:44:47Z")

</div>

[@glilienfield](https://community.neo4j.com/t5/user/viewprofilepage/user-id/9010) hi there

There is only one json file and not more than one json.

You can use the existing json itself, and want to create a main node ( top node) named as main. And that top node should connect with each head node in that json file.

I hope it's clear

---

<div class="post-metadata">

**Author:** ![glilienfield](https://sea1.discourse-cdn.com/flex021/user_avatar/community.neo4j.com/glilienfield/32/27534_2.png) [@glilienfield](https://community.neo4j.com/u/glilienfield)\
**Post date:** [December 26, 2022, 3:45pm UTC](https://community.neo4j.com/t/how-to-form-a-graph-db-from-relation-object/58779/23 "2022-12-26T15:45:01Z")

</div>

Try this:

```auto
MERGE(main:Entity{name:'main'})
WITH main
CALL apoc.load.json("file:///sample.json") YIELD value
UNWIND value.relations as relation
MERGE (head:Entity {name: relation.head})
MERGE (tail:Entity {name: relation.tail})
MERGE (head)-[:HAS_MAIN]->(main)
WITH head, relation, tail, toUpper(replace(relation.type, " ", "_")) as type
CALL apoc.create.relationship(head, type, {}, tail) YIELD rel
RETURN count(rel)

```

 ![Screen Shot 2022-12-26 at 10.42.57 AM.png](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/a/7/a72e1470f0d61b3b299b61749f5f633a16175058.png "Screen Shot 2022-12-26 at 10.42.57 AM.png")

There are only 15 relationships incoming to the main node. This is because your data only has 15 distinct head nodes.

 ![Screen Shot 2022-12-26 at 10.44.39 AM.png](https://us1.discourse-cdn.com/flex021/uploads/neo4jcommunity/original/3X/8/5/8599f2dbbbe416db74b4822c3aa15247a24e94d4.png "Screen Shot 2022-12-26 at 10.44.39 AM.png")

---

<div class="post-metadata">

**Author:** ![Jupyter123](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@Jupyter123](https://community.neo4j.com/u/Jupyter123)\
**Post date:** [December 26, 2022, 4:08pm UTC](https://community.neo4j.com/t/how-to-form-a-graph-db-from-relation-object/58779/24 "2022-12-26T16:08:54Z")

</div>

cheers [@Estelle](https://community.neo4j.com/t5/user/viewprofilepage/user-id/6250) as expected. i really appreciate your time and patience for helping me out.

+1 kudos to you..

---

<div class="post-metadata">

**Author:** ![Jupyter123](https://avatars.discourse-cdn.com/v4/letter/j/8baadc/32.png) [@Jupyter123](https://community.neo4j.com/u/Jupyter123)\
**Post date:** [December 27, 2022, 3:53am UTC](https://community.neo4j.com/t/how-to-form-a-graph-db-from-relation-object/58779/25 "2022-12-27T03:53:03Z")

</div>

[@glilienfield](https://community.neo4j.com/t5/user/viewprofilepage/user-id/9010) thank you very much! it worked!

[Previous page](https://community.neo4j.com/t/how-to-form-a-graph-db-from-relation-object/58779.md?page=1)
