Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Need to rename value inside json files. example: [somefilename123.json]

{"Real/Fake": "Fake", "Fake source": "Print", "Fake Type": "PrintFolded"}

Need to rename value "Print" to "PrintCut"


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
900 views
Welcome To Ask or Share your Answers For Others

1 Answer

import json

with open("some_file.json",'r') as f:
    dict_obj = json.loads(f.read())

dict_obj["Fake source"] = "PrintCut"

with open("some_file.json", "w+") as f:
    f.write(json.dumps(dict_obj, indent = 4))

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...