Skip to content

Instantly share code, notes, and snippets.

@watzon
Last active October 26, 2017 15:46
Show Gist options
  • Save watzon/fc2144bd003d1e6afc9dd78d869683e0 to your computer and use it in GitHub Desktop.
Save watzon/fc2144bd003d1e6afc9dd78d869683e0 to your computer and use it in GitHub Desktop.
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