# Create graph from json file with relation

**URL:** <https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590>\
**Category:** Neo4j Graph Platform\
**Tags:** migrated\
**Created:** [September 25, 2022, 4:36pm UTC](https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590 "2022-09-25T16:36:10Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![hicham](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@hicham](https://community.neo4j.com/u/hicham)\
**Post date:** [September 25, 2022, 4:36pm UTC](https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590/1 "2022-09-25T16:36:10Z")

</div>

Hi I have one problem with my json file (with tokens = nodes and relations)

i need to import token and relation from json file to create graphe thankyou

{  
"text": "CVE-2021-34481",  
"start": 0,  
"end": 14,  
"token\_start": 0,  
"token\_end": 2,  
"entityLabel": "CVE"  
},  
{  
"text": "Windows Print Spooler",  
"start": 15,  
"end": 36,  
"token\_start": 3,  
"token\_end": 5,  
"entityLabel": "SOFTWARE"  
},  
{  
"text": "CVE-2018-0599",  
"start": 75,  
"end": 88,  
"token\_start": 12,  
"token\_end": 14,  
"entityLabel": "CVE"  
},

"relations": [  
{  
"child": 3,  
"head": 0,  
"relationLabel": "CONCERNED\_BY",  
"propertiesList": [

]  
},  
{  
"child": 23,  
"head": 12,  
"relationLabel": "CONCERNED\_BY",  
"propertiesList": [

]  
},

---

<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:** [September 25, 2022, 5:03pm UTC](https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590/2 "2022-09-25T17:03:46Z")

</div>

What does this represent? How is the data in the json related? Do you have data model it is to map too?

---

<div class="post-metadata">

**Author:** ![hicham](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@hicham](https://community.neo4j.com/u/hicham)\
**Post date:** [September 25, 2022, 7:40pm UTC](https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590/3 "2022-09-25T19:40:21Z")

</div>

1 this json file was create with NER annotator for vulnerablity information (cve)

2 the tokens will be the nodes and the end of file you find relations between tokens.

3 i need create graph with this 2 informations (tokens and relationlabel)

4 every relation between head and child

5 head & child ="token\_start" and i need show "entityLabel" in graphe

thank you

---

<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:** [September 25, 2022, 9:19pm UTC](https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590/4 "2022-09-25T21:19:14Z")

</div>

As I understand it:

- each token node is represented by its 'token\_start' property
- each relationship defines its two nodes by its 'head' and 'child' properties, which correspond to the 'start\_token' for each
- each token's 'entityLabel' property represents its label
- each relationship's 'relationLabel' property represents its type

Is this correct?

---

<div class="post-metadata">

**Author:** ![hicham](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@hicham](https://community.neo4j.com/u/hicham)\
**Post date:** [September 26, 2022, 9:32am UTC](https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590/5 "2022-09-26T09:32:15Z")

</div>

hi

yes that's correct thank you

---

<div class="post-metadata">

**Author:** ![hicham](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@hicham](https://community.neo4j.com/u/hicham)\
**Post date:** [September 25, 2022, 11:02pm UTC](https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590/6 "2022-09-25T23:02:23Z")

</div>

Yes  
(migrated from khoros post [Solved: Re: create graph from json file with relation - Neo4j - 60526](https://community.neo4j.com/t5/neo4j-graph-platform/create-graph-from-json-file-with-relation/m-p/60541#M35872))

---

<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:** [September 26, 2022, 11:31am UTC](https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590/7 "2022-09-26T11:31:36Z")

</div>

The json seams to be incomplete. In particular, are the nodes organized in a list like the relationships? Can you provide the full file?

---

<div class="post-metadata">

**Author:** ![hicham](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@hicham](https://community.neo4j.com/u/hicham)\
**Post date:** [September 26, 2022, 8:25pm UTC](https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590/8 "2022-09-26T20:25:23Z")

</div>

i will share file i don't know because i'm beginner in neo4j

[https://drive.google.com/file/d/1wbgXlCWZdBJ1sJag0YJ7HfBA8clAwo3I/view?usp=sharing](https://drive.google.com/file/d/1wbgXlCWZdBJ1sJag0YJ7HfBA8clAwo3I/view?usp=sharing)

---

<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:** [September 27, 2022, 2:51am UTC](https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590/9 "2022-09-27T02:51:53Z")

</div>

I found it easier to create the graph with two queries, one for the nodes and one for the relationships. Run the nodes first.

Node Creation:

```auto
call apoc.load.json("file:///kg4.json")
yield value
unwind value.tokens as token
call apoc.create.node(["Node", token.entityLabel], {token_start: token.token_start, text: token.text}) 
yield node
return node

```

Relationship Creation:

```auto
call apoc.load.json("file:///kg4.json")
yield value
unwind value.relations as relation
match(n:Node{token_start: relation.head})
match(m:Node{token_start: relation.child})
CALL apoc.create.relationship(n, relation.relationLabel, {}, m) 
yield rel
return rel

```

Hope this helps.

---

<div class="post-metadata">

**Author:** ![hicham](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@hicham](https://community.neo4j.com/u/hicham)\
**Post date:** [September 27, 2022, 6:20am UTC](https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590/10 "2022-09-27T06:20:09Z")

</div>

Hello, i have try 2 queries, first one is ok i can create nodes but second i have just table do you know why? please check my result.

Thank you

[https://drive.google.com/file/d/1eNEFgUlLsgaLAHzG-NwC\_\_LJhPvWEk5i/view?usp=sharing](https://drive.google.com/file/d/1eNEFgUlLsgaLAHzG-NwC__LJhPvWEk5i/view?usp=sharing)

[https://drive.google.com/file/d/1W\_DeOcCQLKM3ar1KMy4XQVVo-rsJ3\_Nn/view?usp=sharing](https://drive.google.com/file/d/1W_DeOcCQLKM3ar1KMy4XQVVo-rsJ3_Nn/view?usp=sharing)

---

<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:** [September 27, 2022, 12:48pm UTC](https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590/11 "2022-09-27T12:48:07Z")

</div>

That is just the output of the query, which returns each created relationship. You need to query the database to see the created data.

try:

match(n:Node) return n

---

<div class="post-metadata">

**Author:** ![hicham](https://avatars.discourse-cdn.com/v4/letter/h/e19b73/32.png) [@hicham](https://community.neo4j.com/u/hicham)\
**Post date:** [September 27, 2022, 5:56pm UTC](https://community.neo4j.com/t/create-graph-from-json-file-with-relation/59590/12 "2022-09-27T17:56:05Z")

</div>

Thank you all is good
