Skip to content

Commit e67ff45

Browse files
committed
Fix JSON parsing for example hn.nim.
1 parent b6e0261 commit e67ff45

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

examples/hn/hn.nim

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,9 @@ proc news(id: string) =
4848
box 389, 0, 96, 18
4949
fill "#000000", 0.5
5050
font "IBM Plex Sans", 14, 400, 0, hLeft, vTop
51-
let uri = parseUri(call.json["url"].getStr())
52-
characters "(" & uri.hostname & ")"
51+
if "url" in call.json:
52+
let uri = parseUri(call.json["url"].getStr())
53+
characters "(" & uri.hostname & ")"
5354
textAutoResize tsWidthAndHeight
5455
layoutAlign laCenter
5556
text "title":
@@ -77,7 +78,8 @@ proc news(id: string) =
7778
box 305, 0, 87, 18
7879
fill "#000000", 0.5
7980
font "IBM Plex Sans", 14, 400, 0, hLeft, vTop
80-
characters $call.json["descendants"].getInt() & " comments"
81+
if "descendants" in call.json:
82+
characters $call.json["descendants"].getInt() & " comments"
8183
textAutoResize tsWidthAndHeight
8284
layoutAlign laCenter
8385
text "bar":

0 commit comments

Comments
 (0)