jsongraph / json-graph-specification

A proposal for representing graph structure (nodes / edges) in JSON.
http://jsongraphformat.info/
Other
449 stars 35 forks source link

json-graph-specification

A proposal for representing graph structures in JSON.

Run tests

Changes

Jan 2020 - Updated to Version 2 by Travis Giggy

Jan 2021 - Updated with hypergraph support by mohawk2

Design principles

Structure Overview (Version 2)

nodes object

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.

node object properties

edge array

Edges are an array of objects, each of which represents an edge in the graph.

edge properties

hyperedge array

Hyperedges are either undirected - i.e. a set of nodes - or directed with a set of source nodes, and a set of target nodes

hyperedge properties

graph object

A graph object represents a single conceptual graph.

graph properties

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.

graphs object

A graphs object groups zero or more graph objects into one JSON document.

Examples

Additional examples

empty single graph

{
  "graph": {}
}

empty multi graph

{
  "graphs": []
}

nodes-only single graph

{
  "graph": {
    "nodes": {
      "A": {},
      "B": {}
    }
  }
}

nodes/edges single graph

{
  "graph": {
    "nodes": {
      "A": {},
      "B": {}
    },
    "edges": [
      {
        "source": "A",
        "target": "B"
      }
    ]
  }
}

hyperedges single graph

{
  "graph": {
    "nodes": {
      "A": {},
      "B": {}
    },
    "hyperedges": [
      {
        "nodes": ["A", "B"],
        "relation": "associated",
        "metadata": {}
      }
    ]
  }
}

complete single graph

{
  "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"
        }
      }
    ]
  }
}

complete multi graph

{
  "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"
          }
        }
      ]
    }
  ]
}

Schema

The JSON graph schema(version 2) is provided for the json graph format.

Media Type

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

NPM support

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')

Clients

  1. jay-gee-eff - An npm package for manipulating JGF files in nodejs.
  2. jay-gee-eff-for-web - An npm package for using JGF graphs with OOP in the web, i.e. web browsers, without capabilities of file handling, but a fully fledged JGF feature set.

Project Tests

See TESTING.

Related Standards {#links}

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.

Links