summary refs log tree commit diff stats
path: root/lib/pure/json.nim
diff options
context:
space:
mode:
Diffstat (limited to 'lib/pure/json.nim')
-rw-r--r--lib/pure/json.nim17
1 files changed, 5 insertions, 12 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim
index b033b6316..5f00602cb 100644
--- a/lib/pure/json.nim
+++ b/lib/pure/json.nim
@@ -390,18 +390,10 @@ proc `[]=`*(obj: JsonNode, key: string, val: JsonNode) {.inline.} =
   assert(obj.kind == JObject)
   obj.fields[key] = val
 
-proc `%`*[T: tuple|object](o: T): JsonNode =
+proc `%`*[T: object](o: T): JsonNode =
   ## Construct JsonNode from tuples and objects.
-  ##
-  ## If passed an anonymous tuple, creates `JArray JsonNode`,
-  ## otherwise (named tuples and objects) `JObject JsonNode`.
-  const isNamed = T is object or isNamedTuple(T)
-  when isNamed:
-    result = newJObject()
-    for k, v in o.fieldPairs: result[k] = %v
-  else:
-    result = newJArray()
-    for a in o.fields: result.add(%a)
+  result = newJObject()
+  for k, v in o.fieldPairs: result[k] = %v
 
 proc `%`*(o: ref object): JsonNode =
   ## Generic constructor for JSON data. Creates a new `JObject JsonNode`
@@ -1718,7 +1710,6 @@ when isMainModule:
 
   # Test loading of file.
   when not defined(js):
-    echo("99% of tests finished. Going to try loading file.")
     var parsed = parseFile("tests/testdata/jsontest.json")
 
     try:
@@ -1752,6 +1743,8 @@ when isMainModule:
   doAssert($ %*[] == "[]")
   doAssert($ %*{} == "{}")
 
+  doAssert(not compiles(%{"error": "No messages"}))
+
   # bug #9111
   block:
     type