-2

i try to Pretty print a JSON file, like i have a login system and the "Data" should get save there. But if i use

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

It outputs

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

in the JSON file But it should Print this in the JSON

{
  "username": "censored",
  "password": "censored"
}
LQ MK OnFire
  • 49
  • 3
  • 9

1 Answers1

0

this should work:

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