status-lib/status/utils/json_utils.nim

33 lines
882 B
Nim
Raw Normal View History

2021-09-08 18:05:39 +00:00
import json
template getProp(obj: JsonNode, prop: string, value: var typedesc[int]): bool =
var success = false
if (obj.kind == JObject and obj.contains(prop)):
value = obj[prop].getInt
success = true
success
template getProp(obj: JsonNode, prop: string, value: var typedesc[string]): bool =
var success = false
if (obj.kind == JObject and obj.contains(prop)):
value = obj[prop].getStr
success = true
success
template getProp(obj: JsonNode, prop: string, value: var typedesc[float]): bool =
var success = false
if (obj.kind == JObject and obj.contains(prop)):
value = obj[prop].getFloat
success = true
success
template getProp(obj: JsonNode, prop: string, value: var typedesc[JsonNode]): bool =
var success = false
if (obj.kind == JObject and obj.contains(prop)):
value = obj[prop]
success = true
success