A proposal for representing graph structure (nodes / edges) in JSON.
Ruby
Switch branches/tags
Nothing to show
Clone or download
abargnesi removed BEL JSON Graph Format
moved to its own repository: jsongraph/bel-jsongraph-format

moved tests to the top-level; updated travis
Latest commit e5b0b17 Aug 6, 2015

README.rst

json-graph-specification

A proposal for representing graph structures in JSON.

Links

Continuous Integration

https://travis-ci.org/jsongraph/json-graph-specification.svg?branch=master

Gitter Chat

Design principles

  • Use meaningful property names that reflect the semantic type of the value.
  • Property names should not be excessively long.
  • Property names should be plural when value is an array.
  • Properties that allow a null value can be omitted.
  • Define a JSON graph schema for content validation purposes.

Objects

node object

A node object represents a node in a graph.

node properties

  • An id property is a primary key for an object (see Objects) that is unique for the object type. Its value is defined as a JSON string for flexibility.
  • A label property provides a text display for an object. Its value is defined as a JSON string.
  • A type property provides a classification for an object. Its value is defined as a JSON string.
  • A metadata property allows for custom data on an object. Its values is defined as a JSON object.

edge object

An edge object represents an edge in a graph.

edge properties

  • A source property provides the id value of the source node object. Its value is defined as a JSON string.
  • A relation property provides the interaction between source and target nodes. Its value is defined as a JSON string.
  • A target property provides the id value of the target node object. Its value is defined as a JSON string.
  • A directed property provides the edge mode (e.g. directed or undirected). Its value is JSON true for directed and JSON false for undirected. The edge direction is determined by graph.directed property if not present.
  • A metadata property allows for custom data on an object. Its values is defined as a JSON object.

graph object

A graph object represents a single conceptual graph.

graph properties

  • A type property provides a classification for an object. Its value is defined as a JSON string.
  • A label property provides a text display for an object. Its value is defined as a JSON string.
  • A directed property provides the graph mode (e.g. directed or undirected). Its value is JSON true for directed and JSON false for undirected. This property default to JSON true indicating a directed graph.
  • A nodes property provides the nodes in the graph. Its value is an array of node object.
  • An edges property provides the edges in the graph. Its value is an array of edge object.
  • A metadata property allows for custom data on an object. Its values is defined as a JSON object.

graphs object

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

graphs properties

  • A type property provides a classification for an object. Its value is defined as a JSON string.
  • A label property provides a text display for an object. Its value is defined as a JSON string.
  • A metadata property allows for custom data on an object. Its values is defined as a JSON object.

Examples

empty single graph

{
    "graph": {}
}

empty multi graph

{
    "graphs": []
}

nodes-only single graph

{
    "graph": {
        "nodes": [
            {
                "id": "A",
            },
            {
                "id": "B",
            }
        ]
    }
}

nodes/edges single graph

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

complete single graph

{
    "graph": {
        "directed": false,
        "type": "graph type",
        "label": "graph label",
        "metadata": {
            "user-defined": "values"
        },
        "nodes": [
            {
                "id": "0",
                "type": "node type",
                "label": "node label(0)",
                "metadata": {
                    "user-defined": "values"
                }
            },
            {
                "id": "1",
                "type": "node type",
                "label": "node label(1)",
                "metadata": {
                    "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": [
                {
                    "id": "0",
                    "type": "node type",
                    "label": "node label(0)",
                    "metadata": {
                        "user-defined": "values"
                    }
                },
                {
                    "id": "1",
                    "type": "node type",
                    "label": "node label(1)",
                    "metadata": {
                        "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": [
                {
                    "id": "0",
                    "type": "node type",
                    "label": "node label(0)",
                    "metadata": {
                        "user-defined": "values"
                    }
                },
                {
                    "id": "1",
                    "type": "node type",
                    "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"
                    }
                }
            ]
        }
    ]
}

More real world examples.

Schema

The JSON graph schema (version 3) 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");

Project Tests

See TESTING.

Links