def _prune_dockerfile(string, comment_char="#"):
    """Remove comments, emptylines, and last layer (serialize to JSON)."""
    json_removed = '\n\n'.join(string.split('\n\n')[:-1])
    return '\n'.join(row for row in json_removed.split('\n')
                      if not row.startswith(comment_char) and row)