Last active
October 26, 2017 15:46
-
-
Save watzon/fc2144bd003d1e6afc9dd78d869683e0 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import json, strutils | |
proc toQueryString*(json: JsonNode): string = | |
if json == nil: return "" | |
var parts: seq[string] = @[] | |
for key, val in json: | |
if val.kind != JNull: | |
if val.kind == JString: | |
parts.add(key & "=" & val.getStr().encodeUrl()) | |
else: | |
parts.add(key & "=" & $val) | |
result = "?" & parts.join("&") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment