formats.py 文件源码

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

项目:mssqlcli 作者: rtrox 项目源码 文件源码
def jsonify(obj):
    """
    Convert serializable object to string.

    If Pygments is present, it will be used to colorify the json blob.
    :param list[dict] obj: object to be serialized.
    :returns: serialized json string.
    :rtype: string
    """
    formatted_json = json.dumps(stringify({"results": obj}), indent=4)

    try:
        from pygments import highlight, lexers, formatters
        colorful_json = highlight(
            formatted_json,
            lexers.JsonLexer(),
            formatters.TerminalFormatter()
        )
    except ImportError:
        return formatted_json

    return colorful_json
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号