prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  Annotation answers get parsed incorrectly in csv export
  For annotation type answers, the csv export looks like this currently:
  ![Screenshot from 2021-02-18 16-26-04](https://user-images.githubusercontent.com/57257130/108379339-1b666e00-7206-11eb-8adf-629acca14f74.png)
  
  It appears the annotation json gets part as part of the export. We should probably add some escaping.
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `app/grandchallenge/core/renderers.py`
  Content:
  ```
  1 from rest_framework_csv.renderers import CSVRenderer
  2 
  3 
  4 class PaginatedCSVRenderer(CSVRenderer):
  5     results_field = "results"
  6 
  7     def render(self, data, *args, **kwargs):
  8         if self.results_field in data:
  9             data = data[self.results_field]
  10 
  11         return super().render(data, *args, **kwargs)
  12
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/app/grandchallenge/core/renderers.py b/app/grandchallenge/core/renderers.py
  --- a/app/grandchallenge/core/renderers.py
  +++ b/app/grandchallenge/core/renderers.py
  @@ -1,3 +1,5 @@
  +import json
  +
   from rest_framework_csv.renderers import CSVRenderer
   
   
  @@ -9,3 +11,19 @@
               data = data[self.results_field]
   
           return super().render(data, *args, **kwargs)
  +
  +    def flatten_data(self, data):
  +        """
  +        Create a dictionary that is 1 level deep, with nested values serialized
  +        as json. This means that the header rows are now consistent.
  +        """
  +        for row in data:
  +            flat_row = {k: self._flatten_value(v) for k, v in row.items()}
  +            yield flat_row
  +
  +    @staticmethod
  +    def _flatten_value(value):
  +        if isinstance(value, (dict, list)):
  +            return json.dumps(value)
  +        else:
  +            return value
  
verification_info: {"golden_diff": "diff --git a/app/grandchallenge/core/renderers.py b/app/grandchallenge/core/renderers.py\n--- a/app/grandchallenge/core/renderers.py\n+++ b/app/grandchallenge/core/renderers.py\n@@ -1,3 +1,5 @@\n+import json\n+\n from rest_framework_csv.renderers import CSVRenderer\n \n \n@@ -9,3 +11,19 @@\n             data = data[self.results_field]\n \n         return super().render(data, *args, **kwargs)\n+\n+    def flatten_data(self, data):\n+        \"\"\"\n+        Create a dictionary that is 1 level deep, with nested values serialized\n+        as json. This means that the header rows are now consistent.\n+        \"\"\"\n+        for row in data:\n+            flat_row = {k: self._flatten_value(v) for k, v in row.items()}\n+            yield flat_row\n+\n+    @staticmethod\n+    def _flatten_value(value):\n+        if isinstance(value, (dict, list)):\n+            return json.dumps(value)\n+        else:\n+            return value\n", "issue": "Annotation answers get parsed incorrectly in csv export\nFor annotation type answers, the csv export looks like this currently:\r\n![Screenshot from 2021-02-18 16-26-04](https://user-images.githubusercontent.com/57257130/108379339-1b666e00-7206-11eb-8adf-629acca14f74.png)\r\n\r\nIt appears the annotation json gets part as part of the export. We should probably add some escaping.\n", "before_files": [{"content": "from rest_framework_csv.renderers import CSVRenderer\n\n\nclass PaginatedCSVRenderer(CSVRenderer):\n    results_field = \"results\"\n\n    def render(self, data, *args, **kwargs):\n        if self.results_field in data:\n            data = data[self.results_field]\n\n        return super().render(data, *args, **kwargs)\n", "path": "app/grandchallenge/core/renderers.py"}], "after_files": [{"content": "import json\n\nfrom rest_framework_csv.renderers import CSVRenderer\n\n\nclass PaginatedCSVRenderer(CSVRenderer):\n    results_field = \"results\"\n\n    def render(self, data, *args, **kwargs):\n        if self.results_field in data:\n            data = data[self.results_field]\n\n        return super().render(data, *args, **kwargs)\n\n    def flatten_data(self, data):\n        \"\"\"\n        Create a dictionary that is 1 level deep, with nested values serialized\n        as json. This means that the header rows are now consistent.\n        \"\"\"\n        for row in data:\n            flat_row = {k: self._flatten_value(v) for k, v in row.items()}\n            yield flat_row\n\n    @staticmethod\n    def _flatten_value(value):\n        if isinstance(value, (dict, list)):\n            return json.dumps(value)\n        else:\n            return value\n", "path": "app/grandchallenge/core/renderers.py"}]}