commit 195f4c13d487174cfd66eb8eff30eeceae71625c
parent 53ab193b198365b54bd1301fc0c9e1d7b1608433
Author: Sebastian <sebastian@sebsite.pw>
Date: Wed, 18 May 2022 23:41:14 -0400
encoding::json: add reset function
Signed-off-by: Sebastian <sebastian@sebsite.pw>
Diffstat:
1 file changed, 11 insertions(+), 0 deletions(-)
diff --git a/encoding/json/value.ha b/encoding/json/value.ha
@@ -62,6 +62,17 @@ export fn del(obj: *object, keys: const str...) void = {
};
};
+// Clears all values from a JSON object, leaving it empty.
+export fn reset(obj: *object) void = {
+ let it = iter(obj);
+ for (true) match (next(&it)) {
+ case void =>
+ break;
+ case let v: (const str, const *value) =>
+ del(obj, v.0);
+ };
+};
+
export type iterator = struct {
obj: *object,
i: size,