-1

I have the following code and need to retrieve faq type questions from a bd, how can I convert the list returned to a json, the following code presents: Object of type 'Question' is not JSON serializable

I'm using flask and Python3

@app.route("/faq/<question>")

@app.route("/faq/",defaults={"question":None})

def teste(question):
   r=Question.query.all()

   return jsonify(r)

Object of type 'Question' is not JSON serializable

ncica
  • 7,015
  • 1
  • 15
  • 37
GustavoNogueira
  • 389
  • 1
  • 3
  • 16

1 Answers1

0

Your list contains Question objects that aren't serializable as JSON. If you want the output to be a list of strings, you should use

jsonify(list(map(str, r)))

(This assumes that the question objects can be converted to string.)

Christoph Burschka
  • 4,467
  • 3
  • 16
  • 31