format_utils.py 文件源码

python
阅读 57 收藏 0 点赞 0 评论 0

项目:mlab-vis-api 作者: m-lab 项目源码 文件源码
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
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号