xgi.readwrite.json#

Read from and write to JSON.

Functions

read_json(path, nodetype=None, edgetype=None)[source]#

A function to read a file in a standardized JSON format.

Parameters:
  • data (dict) – A dictionary in the hypergraph JSON format

  • nodetype (type, optional) – type that the node IDs will be cast to

  • edgetype (type, optional) – type that the edge IDs will be cast to

Returns:

The loaded hypergraph. If the dataset chosen is a collection, returns a dictionary of Hypergraph objects.

Return type:

Hypergraph

Raises:

XGIError – If the JSON is not in a format that can be loaded.

write_json(H, path, collection_name='')[source]#

A function to write a file in a standardized JSON format.

If the dataset is a collection, makes local copies of all the datasets in the collection and a main file pointing to all of the datasets.

Parameters:
  • H (Hypergraph object) – The specified hypergraph object

  • path (string) – The path of the file to write to. If the data is a collection, it is the directory in which to put all the files.

  • collection_name (str) – The name of the collection of data (if any). If H is not a collection, this argument is unused.

Raises:

XGIError – If the node or edge IDs have conflicts after casting to strings, e.g., node IDs “2” and 2.