B.1 GraphSON Data Format
The GraphSON file format is based on JavaScript Object Notation (JSON) for describing graphs.
-
The first example in this topic shows a GraphSON description of the property graph shown in What Are Property Graphs?.
-
The second example in this topic shows the GraphSON description of the same graph for Tinkerpop 3.
Example B-1 GraphSON Description of a Simple Property Graph
{ "graph": { "mode":"NORMAL", "vertices": [ { "name": "Alice", "age": 31, "_id": "1", "_type": "vertex" }, { "name": "Bob", "age": 27, "_id": "2", "_type": "vertex" } ], "edges": [ { "type": "friends", "_id": "3", "_type": "edge", "_outV": "1", "_inV": "2", "_label": "knows" } ] } }
Example B-2 GraphSON 3.0 Description of a Simple Property Graph
{"id":{"@type":"g:Int64","@value":1},"label":"person","outE":{"knows":[{"id":{"@type":"g:Int64","@value":3},"inV":{"@type":"g:Int64","@value":2},"properties":{"type":"friends"}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":66724076},"value":"Alice"}],"age":[{"id":{"@type":"g:Int64","@value":96543},"value":{"@type":"g:Int32","@value":31}}]}} {"id":{"@type":"g:Int64","@value":2},"label":"person","inE":{"knows":[{"id":{"@type":"g:Int64","@value":3},"outV":{"@type":"g:Int64","@value":1},"properties":{"type":"friends"}}]},"properties":{"name":[{"id":{"@type":"g:Int64","@value":3440674},"value":"Bob"}],"age":[{"id":{"@type":"g:Int64","@value":96540},"value":{"@type":"g:Int32","@value":27}}]}}
Methods are provided to import and export graphs from and into GraphSON format.
The following fragments of code show how to import and export GraphSON data in Tinkerpop 2 and Tinkerpop 3 versions. Note that the Tinkerpop 3 version has a “Tinkerpop3” suffix. This is to maintain backward compatibility.
// Get graph instance OraclePropertyGraph opg = OraclePropertyGraph.getInstance(args, szGraphName); // Import graph in GraphSON format String fileName = "./mygraph.graphson"; PrintStream ps = new PrintStream("./output"); OraclePropertyGraphUtils.importGraphSON(opg,fileName,ps); // Export graph into GraphSON format String fileName = "./mygraph.graphson"; PrintStream ps = new PrintStream("./output"); OraclePropertyGraphUtils.exportGraphSON(opg,fileName,ps); // Import graph into Tinkerpop 3 GraphSON format String fileName = "./mygraphT3.graphson"; PrintStream ps = new PrintStream("./output"); OraclePropertyGraphUtils.importGraphSONTinkerpop3(opg,fileName,ps); // Export graph into Tinkerpop 3 GraphSON format String fileName = "./mygraphT3.graphson"; PrintStream ps = new PrintStream("./output"); OraclePropertyGraphUtils.exportGraphSONTinkerpop3(opg,fileName,ps);
Related Topics
Parent topic: About Property Graph Data Formats