Head's Up! These forums are read-only. All users and content have migrated. Please join us at community.neo4j.com.
01-19-2021 10:20 AM
Hi everyone! I'm very new at Neo4j.
I'm trying to create a graph from a json file that contains the links for the graph and the nodes.
The "links" section has the number of the source node called "ori_val", and the node's number target for this link called "target".
In the "nodes" section lies the "id" label, wich is the number of the corresponding node for creating it, and this "id" number also is the one used in the "links" section for "ori_val" and "target".
Here is an example of the json file for the first node and link (there are 1138 nodes, and 3553 links):
{
"links": {"0":
"target" : 376,
"value" : 3,
"source" : 0,
"ori_val" : 3,
"type" : "normal"},
"nodes": {"0":
"country": "Guatemala",
"case_id": 0,
"year": "2019",
"id": 0,
"name": "Caso Villaseñor Velarde y otros Vs. Guatemala",
"type": 1 }
}
I tried to built the graph by running this code on the cypher, but it only makes links from all the nodes to just two of them, and all the remainig links between the other nodes are missed.
I've also created the nodes from the file with the label "NODOS".
call apoc.load.json("graph.json") yield value
unwind value.links as l
MATCH (n:NODOS) WHERE n.id=l.ori_val
MATCH (s:NODOS) WHERE s.id=l.target
CREATE (n)-[:Incide]->(s)
Sorry if this is an obvious question, but I've spent too many days trying to solve it and I can´t.
Here's an example of how the graph is displayed for the first 25 nodes, and all the links between the remaining nodes are missed (don't pay attention to the "R" relationship).
Thanks for yout help!
01-19-2021 10:34 AM
Your JSON looks malformed to me [Note: this comment was based on an older version of the question]:
The 0 should be a string and there should be a value after it. Or maybe it should be removed. Or something. Check your log to see if apoc.load.json()
complained about your JSON.
Also, the string values after the keys need to be inside quotes. (e.g. "normal" "Guatemala")
Your JSON flunked this checker: https://jsonlint.com/
{
"links": {0:
"target" : 376,
"value" : 3,
"source" : 0,
"ori_val" : 3,
"type" : normal},
"nodes": {0:
"country": Guatemala,
"case_id": 0,
"year": 2019,
"id": 0,
"name": Caso Villaseñor Velarde y otros Vs. Guatemala
"type": 1 }
}
01-20-2021 09:38 AM
Hi, thanks for your help!
Indeed it is wrong, was a mistake of mine while posting it on here. But the original one has the correct syntaxis.
01-20-2021 09:49 AM
You can edit your original post.
I'm not clear from your post what's exactly your problem is. Can you explain further? Sorry...
01-20-2021 10:17 AM
Sure, no problem.
I'm trying to build a graph with this json.
First you have the "links" section, this tells you all the links your graph must have, in this example you need to build the link from the node with "id"=3, to the node with "id"=376, and so on with the others 3552 links in this json.
On the other hand, you have the "nodes" section, wich tells you all the nodes you have to create, and its properties like "id", "country", etc. I have already created all the nodes from the "nodes" section, with the label "NODOS".
My problem is when I try to build all the links for all the created nodes. I did it with this code:
call apoc.load.json("graph.json") yield value
unwind value.links as l
MATCH (n:NODOS) WHERE n.id=l.ori_val
MATCH (s:NODOS) WHERE s.id=l.target
CREATE (n)-[:Incide]->(s)
But this only makes the links from all the nodes to just two of them: the once with "Corte Interamericana" label, and the other one labeled with "Convencion Americana sobre Derechos". And the other relationships between the remaining nodes are missing, for example the link between "Caso Godínez" and "Caso Herrera" is missed, and so on.
I need to know what am I missing to make all the relationships between the other nodes?
01-20-2021 10:21 AM
It's still broken. the key
"0" :
isn't followed by a proper value
From JSON lint
Error: Parse error on line 3:
...": { "0": "target": 376, "value": 3,
Did you look at the logs? I'm not sure how easy it is for apoc functions to show errors in the browser.
01-21-2021 10:45 AM
Sorry again, here is the good one.
{
"links": {"0": {
"target" : 376,
"value" : 3,
"source" : 0,
"ori_val" : 3,
"type" : "normal"}},
"nodes": {"0": {
"country": "Guatemala",
"case_id": 0,
"year": "2019",
"id": 0,
"name": "Caso Villaseñor Velarde y otros Vs. Guatemala",
"type": 1 }}
}
All the sessions of the conference are now available online