diff --git a/volia/jsoneditor.py b/volia/jsoneditor.py index 1db720d..5a27ed6 100644 --- a/volia/jsoneditor.py +++ b/volia/jsoneditor.py @@ -26,13 +26,14 @@ def write_run(file, jsonpath, content, force): pointer = data for i, way in enumerate(jsonpath): # End of the json path + if i == len(jsonpath) - 1: if not force and way in pointer: raise Exception(f"In your json file, {way} already exists in the path {jsonpath}. Add --force option.") else: # If dictionary in both cases, copy from content to pointer - if type(pointer[way]) is dict and type(content_data) is dict: + if way in pointer and type(pointer[way]) is dict and type(content_data) is dict: for key in content_data: pointer[way][key] = content_data[key] else: @@ -40,8 +41,7 @@ def write_run(file, jsonpath, content, force): else: if way not in pointer: pointer[way] = {} - pointer = pointer[way] - + pointer = pointer[way] # Write the file with open(file, "w") as f: json.dump(data, f)