Python pp Json 配置文件

Python pp a Json config file

我尝试打印一个 JSON 文件,就像我有一个登录系统,“数据”应该保存在那里。 但是如果我使用

          with open('authentication.json', 'w+') as outfile:
              json.dump(data, outfile)

输出

{"username": "censored", "password": "censored"}

在 JSON 文件中 但它应该在 JSON

中打印
{
  "username": "censored",
  "password": "censored"
}

这应该有效:

    import json
    data = {"username": "censored", "password": "censored"}
    with open('authentication.json', 'w+') as outfile:
        json.dump(data, outfile, indent=4, sort_keys=True)