python如何优雅的打印json格式文本

废话不说,直接上代码:

import json


def print_json(data):
    print(json.dumps(data, sort_keys=True, indent=4, separators=(', ', ': '), ensure_ascii=False))


if __name__ == '__main__':
    data = {
        "aaa": {
            "bbb":
                {
                    "vvv": ['541454154', '152125', '151515', {"521515": ""}],
                    "ccc": "i5452126541rl",
                    "cccd": 10
                }
        },
        "12222": {
            "fhvhgvh": "",
            "nbvghngvc": "",
            "nbvg h": "nvhvhv",
        }
    }
    data = ['hngvhgv', ['hngvhgv', 'ngvhngvh'], {'ngvhgv': data}, {'nvjgvjvj': 'jnhvbjvbj'}]

    print("请求:")
    print_json(data)

你可能感兴趣的:(python)