src/hmisc/other/hjson

  Source   Edit

This module provides helper functions for working with json that don't silently ignore errors. If something is missing exception is raised.

  • as* functions - throw exception if node kind does not match (stdlib implementations silently return default value)

Types

JsonConvertOpts = set[JsonConvertOpt]
  Source   Edit

Consts

defaultJsonConvertOptions = {jcoCompactNil, jcoCompactOptions,
                             jcoCompactEmptySeqs, jcoDirectEnumName}
  Source   Edit

Procs

func `%`(c: char): JsonNode {....raises: [], tags: [].}
  Source   Edit
func asBool(node: JsonNode): bool {....raises: [ValueError], tags: [].}
Convert node to bool and throw exception if node kind does not match   Source   Edit
func asFloat(node: JsonNode): float {....raises: [ValueError], tags: [].}
Convert node to float and throw exception if node kind does not match   Source   Edit
func asInt(node: JsonNode): int {....raises: [ValueError], tags: [].}
Convert node to int and throw exception if node kind does not match.   Source   Edit
func asSeq(node: JsonNode): seq[JsonNode] {....raises: [ValueError], tags: [].}
Convert node to sequence and throw exception if kind does not match   Source   Edit
func asStr(node: JsonNode): string {....raises: [ValueError], tags: [].}
Convert node to string and throw exception if node kind does not match   Source   Edit
func asStrSeq(node: JsonNode): seq[string] {....raises: [ValueError], tags: [].}
Convert node to sequence of strings and join them. Throw exception if kind does not match.   Source   Edit
func asTable(node: JsonNode): OrderedTable[string, JsonNode] {.
    ...raises: [ValueError], tags: [].}
Convert node to table and throw exception if kind does not match   Source   Edit
func joinArr(node: JsonNode): string {....raises: [ValueError], tags: [].}
Convert node to list of strings and join them. Throw exception if kind does not mach.   Source   Edit
func toJson(arg: enum; opts: JsonConvertOpts = defaultJsonConvertOptions): JsonNode
  Source   Edit
func toJson(arg: object | tuple | ref object | ref tuple;
            ignoreFields: static[seq[string]];
            opts: JsonConvertOpts = defaultJsonConvertOptions): JsonNode
  Source   Edit
func toJson(arg: object | tuple | ref object | ref tuple;
            opts: JsonConvertOpts = defaultJsonConvertOptions): JsonNode
  Source   Edit
func toJson(arg: openArray[(string, JsonNode)];
            opts: JsonConvertOpts = defaultJsonConvertOptions): JsonNode {.
    ...raises: [], tags: [].}
  Source   Edit
func toJson(arg: string | SomeInteger | bool | float | char;
            opts: JsonConvertOpts = defaultJsonConvertOptions): JsonNode
  Source   Edit
func toJson[K, V](table: Table[K, V]): JsonNode
  Source   Edit
func toJson[T](arg: openArray[(string, T)] | seq[(string, T)];
               opts: JsonConvertOpts = defaultJsonConvertOptions): JsonNode
  Source   Edit
func toJson[T](arg: seq[T] | openArray[T] | set[T];
               opts: JsonConvertOpts = defaultJsonConvertOptions): JsonNode
  Source   Edit
proc toPretty(j: JsonNode; maxWidth: int = 80): string {.
    ...raises: [Exception, KeyError], tags: [RootEffect].}
  Source   Edit

Iterators

iterator items(node: JsonNode): JsonNode {....raises: [], tags: [].}
  Source   Edit