nim-serde/serde/json/parser.nim

16 lines
397 B
Nim
Raw Normal View History

import std/json as stdjson
2024-02-07 09:40:48 +11:00
import pkg/questionable/results
import ./types
2024-02-07 09:40:48 +11:00
{.push raises: [].}
proc parse*(_: type JsonNode, json: string): ?!JsonNode =
# Used as a replacement for `std/json.parseJson`. Will not raise Exception like in the
# standard library
2024-02-07 09:40:48 +11:00
try:
return stdjson.parseJson(json).catch
except Exception as e:
return failure newException(JsonParseError, e.msg, e)