code: def json_requested():
      
      best = request.accept_mimetypes.best_match(
          ['application/json', 'text/html'])
      return (best == 'application/json' and
              request.accept_mimetypes[best] >
              request.accept_mimetypes['text/html'])
docs: Check if json is the preferred output format for the request.