docs: def to_dict(attributes, definitions):
      """Create a dictionary of attributes from a given list of key-value pairs.
      Detects duplicate definitions of the same attribute and raises an exception.
  
      Expects a list of dictionaries (e.g., Json object) objects having 'name'
      and 'value' keys. The type of the element associated with the 'value' key is
      arbitrary. Raises a ValueError exception if the given array violates the
      expected format.
  
      The list of attribute definitions defines the set valid attribute names .
      Raises an ValueError exception if an attribute with an invalid name is
      in the attributes array.
  
      If the list of attributes is None an empty dictionary will be returned.
  
      Parameters
      ----------
      attributes : list()
          Expects a list of Attributes of dictionaries with 'name' and 'value'
          elements.
      definitions: list(dict('id': ..., ...))
          List of attribute definitons.
  
      Returns
      -------
      Dictionary
          Dictionary of attribute instances keyed by their name
      """
      # Create a list of valis parameter names
      valid_names = {}
      for para in definitions:
          valid_names[para.identifier] = para
      result = {}
      if not attributes is None:
          for element in attributes:
              if isinstance(element, dict):
                  # Create attribute from dictionary
                  for key in ['name', 'value']:
                      if not key in element:
                          raise ValueError('object has no key ' + key + ': ' + str(element))
                  name = str(element['name'])
                  if not name in valid_names:
                      raise ValueError('invalid parameter name: ' + name)
                  try:
                      value = valid_names[name].data_type.from_string(
                          element['value']
                      )
                  except ValueError as ex:
                      raise ValueError(str(ex))
                  attr = Attribute(name, value)
              else:
                  # Element is expected to be an attribute object
                  attr = element
                  # Make sure that the attribute value is of valid type. Make
                  # sure that attr.name is valid.
                  if attr.name in valid_names:
                      valid_names[attr.name].data_type.test_value(attr.value)
                  else:
                      raise ValueError('invalid parameter name: ' + attr.name)
              if attr.name in result:
                  raise ValueError('duplicate attribute: ' + attr.name)
              result[attr.name] = attr
      return result