docs: def json_serializer(data=None, code=200, headers=None, context=None,
                      etag=None, task_result=None):
      """Build a json flask response using the given data.
  
      :param data: The data to serialize. (Default: ``None``)
      :param code: The HTTP status code. (Default: ``200``)
      :param headers: The HTTP headers to include. (Default: ``None``)
      :param context: The schema class context. (Default: ``None``)
      :param etag: The ETag header. (Default: ``None``)
      :param task_result: Optionally you can pass async task to wait for.
          (Default: ``None``)
      :returns: A Flask response with json data.
      :rtype: :py:class:`flask.Response`
      """
      schema_class, many = schema_from_context(context or {})
  
      if data is not None:
          # Generate JSON response
          data = json.dumps(
              schema_class(context=context).dump(data, many=many).data,
              **_format_args()
          )
  
          interval = current_app.config['FILES_REST_TASK_WAIT_INTERVAL']
          max_rounds = int(
              current_app.config['FILES_REST_TASK_WAIT_MAX_SECONDS'] // interval
          )
  
          response = current_app.response_class(
              # Stream response if waiting for task result.
              data if task_result is None else wait_for_taskresult(
                  task_result, data, interval, max_rounds, ),
              mimetype='application/json'
          )
      else:
          response = current_app.response_class(mimetype='application/json')
  
      response.status_code = code
      if headers is not None:
          response.headers.extend(headers)
  
      if etag:
          response.set_etag(etag)
  
      return response