From 4099abc8675ca37e713098c211bfe73aabd34259 Mon Sep 17 00:00:00 2001 From: Billingsly Wetherfordshire Date: Sat, 3 May 2014 16:49:41 -0500 Subject: [PATCH] added `==` for PJsonNode --- lib/pure/json.nim | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/lib/pure/json.nim b/lib/pure/json.nim index 4250847e56..b325c2905d 100644 --- a/lib/pure/json.nim +++ b/lib/pure/json.nim @@ -619,6 +619,25 @@ proc `%`*(elements: openArray[PJsonNode]): PJsonNode = newSeq(result.elems, elements.len) for i, p in pairs(elements): result.elems[i] = p +proc `==`* (a,b: PJsonNode): bool = + if a.kind != b.kind: false + else: + case a.kind + of JString: + a.str == b.str + of JInt: + a.num == b.num + of JFloat: + a.fnum == b.fnum + of JBool: + a.bval == b.bval + of JNull: + true + of JArray: + a.elems == b.elems + of JObject: + a.fields == b.fields + 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.