Inspired by this question, I'm trying to represent a DAG in JSON. My case includes edges and nodes that contain some data (rather than just strings as in this example). I was thinking of a spec like this:
{
"graph": {
"a": ["b", "c"],
"b": ["c"]
"c"
},
"nodes": {
"a": {
"name": "Adam"
},
"b": {
"name": "Bob"
},
"c": {
"name": "Caillou"
}
},
"edges": {
// how to do the same for edges?
// ie: how to query edges ?
}
}
One idea I had was to make the keys of the edges be the concatenation of the two vertex ids that it connects. For example, ab
, ac
, and bc
are the three edges in this graph. I want to know if there's a more standard way of doing this.
EDIT: This is what I'm thinking of now
{
"graph": {
"a": {
"data": {
// a's vertex data
},
"neighbors": {
"b": {
"data": {
// data in edge ab
}
},
"c": {
"data": {
// data in edge ac
}
}
}
},
"b": {
"data": {
// b's vertex data
},
"neighbors": {
"c": {
"data": {
// data in edge bc
}
}
}
},
"c": {
"data": {
// c's vertex data
}
}
}
}
What is JSON Graph? JSON Graph is a convention for modeling graph information as a JSON object. Applications that use Falcor represent all their domain data as a single JSON Graph object. JSON Graph is valid JSON and can be parsed by any JSON parser.
JavaScript Object Notation (JSON) is a standard text-based format for representing structured data based on JavaScript object syntax. It is commonly used for transmitting data in web applications (e.g., sending some data from the server to the client, so it can be displayed on a web page, or vice versa).
Since the DAG's edges hold data, they better have their own identifiers, just like the nodes. That is, the json representation should be composed of three components:
Adjacency lists: mapping each node identifier to an array of edge identifiers, each corresponds to an edge going out of the node.
DAG = {
"adjacency": {
"a": ["1", "2"],
"b": ["3"]
},
"nodes": {
"a": {
// data
},
"b": {
// data
},
"c": {
// data
}
},
"edges": {
"1": {
"from": "a", "to": "b",
"data": {
// data
}
},
"2": {
"from": "a", "to": "b",
"data": {
// data
}
},
"3": {
"from": "b", "to": "c",
"data": {
// data
}
}
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With