I'm newbie in Python and struggling with function that changes nested Json values. Now I've this:
def change_json(key, new_value, json_body):
file = open(json_body, "r")
json_object = json.load(file)
file.close()
json_object[key] = new_value
file = open(json_body, "w")
json.dump(json_object, file)
file.close()
It works perfect if json has simple structure, like this:
{
"A": "test"
}
But I don't know how to point nested fields, like this:
{
"data":{
"A": "test"
}
}
I'd like smth like this:
change_json(["data"]["A"], "test2", xyz.json)
In next step I'm going to implement this function with lists - I would pass list of keys and list of values which has same amount of variables.
Thanks for help :) Happy Xmas guys