def get_json_attr(obj):
  """
  Returns the serialized version of the object if it has to_json() defined
  """
  if hasattr(obj, "to_json"):
    return getattr(obj, "to_json")()
  else:
    return obj