import gzip
import json


def read_json(filename):
  """
  Read a JSON file.

  Parameters
  ----------
  filename : str
    Filename. Must be of type .json or .json.gz.
  """
  if filename.endswith('json.gz'):
    with gzip.open(filename) as f:
      tree = json.load(f)
  elif filename.endswith('.json'):
    with open(filename) as f:
      tree = json.load(f)
  else:
    raise ValueError('Filename must be of type .json or .json.gz.')
  return tree