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
ichał Zieliński <michal@zielinscy.org.pl> 2013-12-11 22:27:39 +0100 Use quoteShell in stdlib, where appropriate.' href='/ahoang/Nim/commit/compiler/nimrod.nim?h=devel&id=39cabcdd2702098825eba32fcbc6737b9aa45e6e'>39cabcdd2 ^
fd62116f6 ^





c617479c6 ^
2df9b442c ^
73919e308 ^
e25474154 ^
fc9fdc2b9 ^
e25474154 ^
92b8fac94 ^
fc9fdc2b9 ^
ae0ab9a10 ^
e4e74034c ^
c617479c6 ^
fc9fdc2b9 ^



c617479c6 ^
e4e74034c ^
2df9b442c ^
3b7ef2288 ^

e25474154 ^
2df9b442c ^

e25474154 ^
73919e308 ^
627e192f6 ^



fc9fdc2b9 ^
1785c6877 ^
b0a16fb61 ^





01dfcf631 ^
fe285b354 ^
3b38ceac2 ^





438703f59 ^
3b38ceac2 ^
01dfcf631 ^
e25474154 ^
4aba7421f ^

65fdd641a ^
3d7abb958 ^
65fdd641a ^

b731e6ef1 ^
1e26047c3 ^

2df9b442c ^
1e26047c3 ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92