Commit b6c178927ea5fc74f5bddc820baef58ddd840319

Authored by quillotm
1 parent 91758e85fb
Exists in master

Solve issue: trying to get pointer[way] when the way does not exists.

Showing 1 changed file with 3 additions and 3 deletions Side-by-side Diff

... ... @@ -26,13 +26,14 @@
26 26 pointer = data
27 27 for i, way in enumerate(jsonpath):
28 28 # End of the json path
  29 +
29 30 if i == len(jsonpath) - 1:
30 31  
31 32 if not force and way in pointer:
32 33 raise Exception(f"In your json file, {way} already exists in the path {jsonpath}. Add --force option.")
33 34 else:
34 35 # If dictionary in both cases, copy from content to pointer
35   - if type(pointer[way]) is dict and type(content_data) is dict:
  36 + if way in pointer and type(pointer[way]) is dict and type(content_data) is dict:
36 37 for key in content_data:
37 38 pointer[way][key] = content_data[key]
38 39 else:
... ... @@ -40,8 +41,7 @@
40 41 else:
41 42 if way not in pointer:
42 43 pointer[way] = {}
43   - pointer = pointer[way]
44   -
  44 + pointer = pointer[way]
45 45 # Write the file
46 46 with open(file, "w") as f:
47 47 json.dump(data, f)