src/jsonpatch/jsonpointer

This module implements JSON pointers according to RFC 6901.

Types

JsonPointer = object
  segments: seq[string]
JsonContainerKind {.pure.} = enum
  JsonObject, JsonArray
JsonPointerKey = object
  case kind*: JsonContainerKind
  of JsonObject:
    member*: string
  of JsonArray:
    idx*: int
  
JsonPointerError = object of CatchableError

Procs

func toJsonPointer(jsonPointer: string): JsonPointer {.
    ...raises: [JsonPointerError, ValueError], tags: [].}
See https://tools.ietf.org/html/rfc6901
proc `$`(p: JsonPointer): string {....raises: [], tags: [].}
func parent(jsonPointer: JsonPointer): Option[JsonPointer] {....raises: [],
    tags: [].}
func parseChildKey(node: JsonNode; segment: string): JsonPointerKey {.
    ...raises: [JsonPointerError, ValueError, JsonPointerError, ValueError],
    tags: [].}
func leafSegment(p: JsonPointer): Option[string] {....raises: [], tags: [].}
Returns the last segment of the pointer, if it exists
func resolve(root: JsonNode; jsonPointer: JsonPointer): Option[JsonNode] {.
    ...raises: [JsonPointerError, ValueError], tags: [].}
Returns the parent of the node which is represented by given JSON Pointer.
func resolve(root: JsonNode; jsonPointer: string): Option[JsonNode] {.
    ...raises: [JsonPointerError, ValueError], tags: [].}
Returns the parent of the node which is represented by given string, interpreted as JSON Pointer.
func isRoot(p: JsonPointer): bool {....raises: [], tags: [].}
func `/`(p1, p2: JsonPointer): JsonPointer {....raises: [], tags: [].}
Concatenate pointers
func `/`(p1: JsonPointer; p2: string): JsonPointer {.
    ...raises: [JsonPointerError, ValueError], tags: [].}
Concatenate pointers while converting second argument to JsonPointer
proc `%`(p: JsonPointer): JsonNode {....raises: [], tags: [].}
proc to[T: JsonPointer](node: JsonNode; t: typedesc[T]): T