def METHOD_NAME(net, filename=None, encryption_key=None):
    """
    Saves a pandapipes Network in JSON format. The index columns of all pandas DataFrames will be
    saved in ascending order. net elements which name begins with "_" (internal elements) will not
    be saved. Std types will also not be saved.
    :param net: The pandapipes Network to save.
    :type net: pandapipesNet
    :param filename: The absolute or relative path to the output file or a writable file-like \
            object. If None, a JSON string is returned.
    :type filename: str, file-object, default None
    :param encryption_key: If given, the pandapipes network is stored as an encrypted json string
    :type encryption_key: str, default None
    :return: JSON string of the Network (only if filename is None)
    :Example:
        >>> pandapipes.to_json(net, "example.json")
    """
    json_string = json.dumps(net, cls=PPJSONEncoder, indent=2, isinstance_func=isinstance_partial)
    if encryption_key is not None:
        json_string = encrypt_string(json_string, encryption_key)
    if filename is None:
        return json_string
    if hasattr(filename, 'write'):
        filename.write(json_string)
    else:
        with open(filename, "w") as fp:
            fp.write(json_string)