PythonでJSONファイルを扱う
ファイルを読み書きする
code:sample.py
deepFilepath = "json/hoge.json"
with open(deepFilepath) as f:
#辞書(オブジェクト)として読み込む
filedics = json.load(f)
#何かしらの処理(update,append)
# JSONファイルとして保存(インデント付与)
with open(deepFilepath, "w") as f:
json.dump(filedics, f, indent=4,ensure_ascii=False)
ref.
Pythonでjsonデータに追加する方法 - ALL Python(オールパイソン)
PythonでJSONファイル・文字列の読み込み・書き込み | note.nkmk.me
Pythonで辞書に要素を追加・更新 | note.nkmk.me