summary refs log tree commit diff stats
path: root/lib/pure/json.nim
diff options
context:
space:
mode:
authordom96 <dominikpicheta@googlemail.com>2011-05-14 20:32:31 +0100
committerdom96 <dominikpicheta@googlemail.com>2011-05-14 20:32:31 +0100
commitd1cd1cea345e82ff1f8b55803b81d68a86cb9d50 (patch)
treeded8f8c61d85178677ac6ed4ff3c84a71624a518 /lib/pure/json.nim
parent74b1b28f7e8d832a002502011e800405dedfb6dd (diff)
downloadNim-d1cd1cea345e82ff1f8b55803b81d68a86cb9d50.tar.gz
fixed some redis commands; fixed bindAddr and scgi now doesn't bind to all addresses. copy and delete for json module.
Diffstat (limited to 'lib/pure/json.nim')
-rwxr-xr-xlib/pure/json.nim29
1 files changed, 29 insertions, 0 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim
index 75958a55f..adb7e5e8b 100755
--- a/lib/pure/json.nim
+++ b/lib/pure/json.nim
@@ -606,6 +606,35 @@ proc `[]=`*(obj: PJsonNode, key: String, val: PJsonNode) =
       return
   obj.fields.add((key, val))
 
+proc delete*(obj: PJsonNode, key: string) =
+  assert(obj.kind == JObject)
+  for i in 0..obj.fields.len-1:
+    if obj.fields[i].key == key:
+      obj.fields.delete(i)
+      return
+  raise newException(EInvalidIndex, "key not in object")
+
+proc copy*(p: PJsonNode): PJsonNode =
+  case p.kind
+  of JString:
+    result = newJString(p.str)
+  of JInt:
+    result = newJInt(p.num)
+  of JFloat:
+    result = newJFloat(p.fnum)
+  of JBool:
+    result = newJBool(p.bval)
+  of JNull:
+    result = newJNull()
+  of JObject:
+    result = newJObject()
+    for key, field in items(p.fields):
+      result.fields.add((key, copy(field)))
+  of JArray:
+    result = newJArray()
+    for i in items(p.elems):
+      result.elems.add(copy(i))
+
 # ------------- pretty printing ----------------------------------------------
 
 proc indent(s: var string, i: int) =