Skip to content

Commit 9a1a2e7

Browse files
authored
Merge pull request #140 from ihor-hrytskiv/fix/set-obj
fix: set_obj
2 parents b236ac6 + 2711161 commit 9a1a2e7

File tree

3 files changed

+9
-4
lines changed

3 files changed

+9
-4
lines changed

jsonpatch/kcl.mod

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
[package]
22
name = "jsonpatch"
3-
version = "0.0.3"
3+
version = "0.0.4"
44
description = "`jsonpatch` is a module for applying JSON patches (RFC 6902) for KCL values."
55

jsonpatch/main.k

+2-1
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,17 @@ _build_patch_obj_n = lambda obj: {str:}, value: any, elements: [str], n: int ->
6060
assert current_obj not in NULL_CONSTANTS, "list value not found for path: ${current_path}"
6161
if n + 1 < len(elements):
6262
next_key = _get_list_index_from_key(elements[n + 1])
63-
next_val = _build_patch_obj_n(obj, value, elements, n + 2)
6463
# List key
6564
if next_key not in NULL_CONSTANTS:
65+
next_val = _build_patch_obj_n(obj, value, elements, n + 2)
6666
idx = next_key
6767
assert 0 <= idx < len(current_obj), "value not found for path: {}".format(current_path + "/" + elements[n + 1])
6868
result = {
6969
"${elements[n]}": [None] * idx + [next_val] + [None] * (len(current_obj) - 1 - idx)
7070
}
7171
# Config key
7272
else:
73+
next_val = _build_patch_obj_n(obj, value, elements, n + 1)
7374
result = {
7475
"${elements[n]}": next_val
7576
}

jsonpatch/main_test.k

+6-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,11 @@ test_json_patch = lambda {
2121
]
2222
}
2323
phoneNumbers0type: str = get_obj(data, "phoneNumbers/0/type")
24-
newObj = set_obj(data, "phoneNumbers/0/type", "school")
24+
addressCity: str = get_obj(data, "address/city")
25+
newType = set_obj(data, "phoneNumbers/0/type", "school")
26+
newState = set_obj(data, "address/state", "WA")
2527
assert phoneNumbers0type == "home"
26-
assert newObj["phoneNumbers"][0]["type"] == "school"
28+
assert addressCity == "New York"
29+
assert newType["phoneNumbers"][0]["type"] == "school"
30+
assert newState["address"]["state"] == "WA"
2731
}

0 commit comments

Comments
 (0)