def convert_to_json(data):
'''
Encode the data as JSON -- taken from
flask_restplus.representations.output_json -- updated to clean the
dictionary of nulls.
'''
settings = current_app.config.get('RESTPLUS_JSON', {})
# If we're in debug mode, and the indent is not set, we set it to a
# reasonable value here. Note that this won't override any existing value
# that was set. We also set the "sort_keys" value.
if current_app.debug:
settings.setdefault('indent', 4)
settings.setdefault('sort_keys', True)
# always end the json dumps with a new line
# see https://github.com/mitsuhiko/flask/pull/1262
dumped = dumps(cleandict(data), **settings) + "\n"
return dumped
评论列表
文章目录