A proposal for representing graph structures in JSON.
Jan 2020 - Updated to Version 2 by Travis Giggy
Jan 2021 - Updated with hypergraph support by mohawk2
null
value can be omitted.A nodes object/Map represents nodes in a graph. Each key in the nodes object is the unique identifier for the node. The node object is the value the Map key.
Edges are an array of objects, each of which represents an edge in the graph.
Hyperedges are either undirected - i.e. a set of nodes - or directed with a set of source nodes, and a set of target nodes
A graph object represents a single conceptual graph.
Current restriction on having one of edges, undirected hyperedges or directed hyperedges. If this is not a useful restriction, please post a use case in the Issues.
A graphs object groups zero or more graph objects into one JSON document.
{
"graph": {}
}
{
"graphs": []
}
{
"graph": {
"nodes": {
"A": {},
"B": {}
}
}
}
{
"graph": {
"nodes": {
"A": {},
"B": {}
},
"edges": [
{
"source": "A",
"target": "B"
}
]
}
}
{
"graph": {
"nodes": {
"A": {},
"B": {}
},
"hyperedges": [
{
"nodes": ["A", "B"],
"relation": "associated",
"metadata": {}
}
]
}
}
{
"graph": {
"directed": false,
"type": "graph type",
"label": "graph label",
"metadata": {
"user-defined": "values"
},
"nodes": {
"0": {
"label": "node label(0)",
"metadata": {
"type": "node type",
"user-defined": "values"
}
},
"1": {
"label": "node label(1)",
"metadata": {
"type": "node type",
"user-defined": "values"
}
}
},
"edges": [
{
"source": "0",
"relation": "edge relationship",
"target": "1",
"directed": false,
"label": "edge label",
"metadata": {
"user-defined": "values"
}
}
]
}
}
{
"graphs": [
{
"directed": true,
"type": "graph type",
"label": "graph label",
"metadata": {
"user-defined": "values"
},
"nodes": {
"0": {
"label": "node label(0)",
"metadata": {
"type": "node type",
"user-defined": "values"
}
},
"1": {
"label": "node label(1)",
"metadata": {
"type": "node type",
"user-defined": "values"
}
}
},
"edges": [
{
"source": "0",
"relation": "edge relationship",
"target": "1",
"directed": true,
"label": "edge label",
"metadata": {
"user-defined": "values"
}
}
]
},
{
"directed": true,
"type": "graph type",
"label": "graph label",
"metadata": {
"user-defined": "values"
},
"nodes": {
"0": {
"label": "node label(0)",
"metadata": {
"user-defined": "values"
}
},
"1": {
"label": "node label(1)",
"metadata": {
"user-defined": "values"
}
}
},
"edges": [
{
"source": "1",
"relation": "edge relationship",
"target": "0",
"directed": true,
"label": "edge label",
"metadata": {
"user-defined": "values"
}
}
]
}
]
}
The JSON graph schema(version 2) is provided for the json graph format.
The media type to describe JSON Graph Format is application/vnd.jgf+json. The approach to use a media type suffix like +json is described by RFC 6839.
In addition to the media type a profile media type parameter MUST be set to a URL that dereferences to the JSON schema for JSON Graph Format. The expected usage of the profile media type parameter is defined by RFC 6906. For example to communicate plain JSON Graph Format content the Content-Type header could be set as:
Content-Type: application/vnd.jgf+json
A child schema of JSON Graph Format can communicate its JSON schema using additional profile media type parameters. Each profile media type parameter MUST dereference a JSON schema. For example the BEL JSON Graph Format could be communicated as:
Content-Type: application/vnd.jgf+json;
profile=http://jsongraphformat.info/schema.json;
profile=http://jsongraphformat.info/child-schemas/bel-json-graph.schema.json
You can import the schema into your JS projects by installing it via NPM and requiring it.
npm install --save json-graph-specification
var JSONGraph = require('json-graph-specification')
See TESTING.
Graph data in JSON is usually modelled in application-specific ad-hoc formats. In addition there are several text-based graph formats:
and XML-based graph formats:
Several semi-standardized JSON-based graph formats are found in applications, for instance Cytoscape JSON. Simple graphs can also be expressed in CSV format.