Converting mongoengine objects to JSON Converting mongoengine objects to JSON flask flask

Converting mongoengine objects to JSON


Your query returns a queryset. Use the .to_json() method to convert it.

Depending on what you need from there, you may want to use something like json.loads() to get a python dictionary.

For example:

from model import Users# This returns <class 'mongoengine.queryset.queryset.QuerySet'>q_set = Users.objects()json_data = q_set.to_json()# You might also find it useful to create python dictionariesimport jsondicts = json.loads(json_data)