I have a json file that defines the nodes and their relationships. It looks sometihng like this:
{"p":{"type":"node","id":"0","labels":["Paintings"],"properties":{"date":"1659-01-01T00:00:00","img":"removed-for-brevity(RFB)","name":"King Caspar","sitelink":"1","description":"RFB","exhibit":"RAB","uri":"RFB"}},"r":{"id":"144","type":"relationship","label":"on_MATERIAL","start":{"id":"0","labels":["Paintings"]},"end":{"id":"2504","labels":["Material"]}},"n":{"type":"node","id":"2504","labels":["Material"],"properties":{"name":"oak","sitelink":5,"description":"RFB","uri":"RFB"}}}
"p" is the first node, "r" is the relationship, "n" is the second node.
Is it possible for neo4j to create a graph/map automatically from this json file, without having to define the nodes and relationships through cypher manually?
I am fairly new to neo4j, I tried following the examples given on the Load JSON page, but it defines the nodes and their relationships manually, which i want to avoid.
2
Answers
It looks like neo4j can't automatically create a graph data model using a json file (as @cybersam pointed out earlier).
I ended up writing a Python script to do this for me. Posting this here just in case it helps someone. It does the job for me!
No, there is no automated way, and even if there were the generated result could be suboptimal or even wrong for your use cases.
You need to design the graph data model (node labels, relationship types, etc.) yourself. There are many considerations (like your use cases, and the necessary indexes and constraints) that are not revealed by a simple JSON data dump. Also, you need to understand the schema of the JSON and determine how to map that to your data model.