diff options
-rw-r--r-- | lib/pure/json.nim | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim index b325c2905..c56589803 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -620,6 +620,7 @@ proc `%`*(elements: openArray[PJsonNode]): PJsonNode = for i, p in pairs(elements): result.elems[i] = p proc `==`* (a,b: PJsonNode): bool = + ## Check two nodes for equality if a.kind != b.kind: false else: case a.kind @@ -638,6 +639,24 @@ proc `==`* (a,b: PJsonNode): bool = of JObject: a.fields == b.fields +proc hash* (n:PJsonNode): THash = + ## Compute the hash for a JSON node + case n.kind + of jArray: + result = hash(n.elems) + of jObject: + result = hash(n.fields) + of jInt: + result = hash(n.num) + of jFloat: + result = hash(n.fnum) + of jBool: + result = hash(n.bval.int) + of jString: + result = hash(n.str) + of jNull: + result = hash(0) + proc len*(n: PJsonNode): int = ## If `n` is a `JArray`, it returns the number of elements. ## If `n` is a `JObject`, it returns the number of pairs. |