login.microsoftonline.com
该函数给了我一个json输出。我想创建一个文件,其中json输出将被格式化,以便我可以分析数据。有点像我们可以用https://jsonformatter.curiousconcept.com/做的。
我怎么能这样做?我已经看到了这个问题How to prettyprint a JSON file?,但我无法根据自己的想法调整回应。
答案 0 :(得分:2)
你很幸运,因为这在python中是很常见的事情。
import json
... # Existing code
data = response.json() # Requests has a built in json response parser
with open("my_stylish_file.json", "w") as f:
json.dump(data, f, indent=4)
# The 'indent' is what makes it multiline and automatically indented