GraphSON是一种用于表示图数据的JSON格式。它基于JSON(JavaScript Object Notation)格式,使得图数据能够以易于理解和交换的方式在不同的系统和应用之间进行传输和处理。
以下是一个简单的GraphSON示例,表示一个包含两个节点和一条边的图:
{
"nodes": [
{ "id": "1", "label": "Person", "properties": { "name": "Alice" } },
{ "id": "2", "label": "Person", "properties": { "name": "Bob" } }
],
"edges": [
{ "id": "e1", "outV": "1", "inV": "2", "label": "KNOWS", "properties": { "since": 2020 } }
]
}
可以使用JavaScript来解析和处理GraphSON数据:
const graphsonData = {
"nodes": [
{ "id": "1", "label": "Person", "properties": { "name": "Alice" } },
{ "id": "2", "label": "Person", "properties": { "name": "Bob" } }
],
"edges": [
{ "id": "e1", "outV": "1", "inV": "2", "label": "KNOWS", "properties": { "since": 2020 } }
]
};
graphsonData.nodes.forEach(node => {
console.log(`Node ID: ${node.id}, Label: ${node.label}, Name: ${node.properties.name}`);
});
graphsonData.edges.forEach(edge => {
console.log(`Edge ID: ${edge.id}, From: ${edge.outV}, To: ${edge.inV}, Label: ${edge.label}, Since: ${edge.properties.since}`);
});
通过这种方式,可以方便地处理和操作图数据。