code: def json_handler(cls, func):
          
          @cls.handler
          @functools.wraps(func)
          def wrapper(self, request, suffix=''):
              """The wrapper function `json_handler` returns."""
              if request.method != "POST":
                  return JsonHandlerError(405, "Method must be POST").get_response(allow=["POST"])
              try:
                  request_json = json.loads(request.body)
              except ValueError:
                  return JsonHandlerError(400, "Invalid JSON").get_response()
              try:
                  response = func(self, request_json, suffix)
              except JsonHandlerError as err:
                  return err.get_response()
              if isinstance(response, Response):
                  return response
              else:
                  return Response(json.dumps(response), content_type='application/json', charset='utf8')
          return wrapper
docs: Wrap a handler to consume and produce JSON.
  
          Rather than a Request object, the method will now be passed the
          JSON-decoded body of the request. The request should be a POST request
          in order to use this method. Any data returned by the function
          will be JSON-encoded and returned as the response.
  
          The wrapped function can raise JsonHandlerError to return an error
          response with a non-200 status code.
  
          This decorator will return a 405 HTTP status code if the method is not
          POST.
          This decorator will return a 400 status code if the body contains
          invalid JSON.