You can make use of Cypher Queries to load your data into an Apache AGE graph.
-- Create the graph
CREATE GRAPH mygraph;
-- Load the vertices
CALL apoc.load.json('file:///path/to/your/data.json') YIELD value
UNWIND value.vertices AS vertex
MERGE (n:Person {id: vertex.id})
SET n.name = vertex.properties.name,
n.age = vertex.properties.age;
-- Load the edges
CALL apoc.load.json('file:///path/to/your/data.json') YIELD value
UNWIND value.edges AS edge
MATCH (source:Person {id: edge.source})
MATCH (target:Person {id: edge.target})
CREATE (source)-[r:FRIENDS_WITH {since: edge.properties.since}]->(target);
Make sure to replace 'file:///path/to/your/data.json'
with the actual path to your JSON data file.
In these queries, the apoc.load.json
procedure is used to load the JSON data. The UNWIND
clause is used to iterate over the vertices and edges arrays in the JSON data. The MERGE
statement is used to create or match the vertices, and the SET
clause assigns the properties to the vertices. For edges, the MATCH
clause is used to find the source and target vertices, and the CREATE
statement is used to create the relationships.
You can use the age-viewer
tool to view the data in the graph. To do this, you will need to open the age-viewer tool and select the Add Graph option. In the Add Graph dialog box, specify the name of the graph (mygraph) and the location of the graph database (~/.age/mygraph). Click on the Open button.
The age-viewer tool will display the graph in a graphical format. You can use the Query tab to enter Cypher queries to explore the data.