import json


def model_to_json(model, filename="", indent=None):
    """Converts model to JSON as string or file"""
    json_model = json.dumps(model, indent=indent)
    if filename != "":
        json_file = open(filename, "w")
        json_file.write(json_model)
    return json_model