import json


def to_json(config):
  """Converts a JSON-serializable configuration object to a JSON string."""
  if hasattr(config, "to_json") and callable(config.to_json):
    return config.to_json(indent=2)
  else:
    return json.dumps(config, indent=2)