From b6c178927ea5fc74f5bddc820baef58ddd840319 Mon Sep 17 00:00:00 2001 From: quillotm Date: Thu, 19 Aug 2021 12:54:34 +0200 Subject: [PATCH] Solve issue: trying to get pointer[way] when the way does not exists. --- volia/jsoneditor.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) 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) -- 1.8.2.3