def METHOD_NAME(self, fname=None):
    if fname is not None:
        with open(fname, "w") as f:
            json.dump(self.to_dict(), f, indent=4)
    else:
        return json.dumps(self.to_dict(), indent=4)