You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
### `proc renameHook()` Can be used to rename fields at run time.
@@ -156,7 +156,7 @@ proc renameHook(v: var Node, fieldName: var string) =
156
156
if fieldName == "type":
157
157
fieldName = "kind"
158
158
159
-
var node = fromJson[Node]("""{"type":"root"}""")
159
+
var node = """{"type":"root"}""".fromJson(Node)
160
160
doAssert node.kind == "root"
161
161
```
162
162
@@ -171,7 +171,7 @@ proc parseHook(s: string, i: var int, v: var DateTime) =
171
171
parseHook(s, i, str)
172
172
v = parse(str, "yyyy-MM-dd hh:mm:ss")
173
173
174
-
var dt = fromJson[DateTime](""" "2020-01-01 00:00:00" """)
174
+
var dt = """ "2020-01-01 00:00:00" """.fromJson(DateTime)
175
175
```
176
176
177
177
Sometimes json gives you an object of entries with their id as keys, but you might want it as a sequence with ids inside the objects. You can handle this and many other scenarios with `parseHook()`:
@@ -195,7 +195,7 @@ proc parseHook(s: string, i: var int, v: var seq[Entry]) =
0 commit comments