jsonutils

package
v0.31.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jun 2, 2024 License: Apache-2.0 Imports: 3 Imported by: 0

Documentation

Overview

Package jsonutils provides functions for retrieving and converting values from unmarshalled JSON data structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BytesAtKey

func BytesAtKey(jm map[string]any, k string) ([]byte, error)

BytesAtKey returns the requested key value as a slice of bytes.

func IntAtKey

func IntAtKey(jm map[string]any, k string) (int, error)

IntAtKey returns the requested key value as an int.

func MapAtKey

func MapAtKey(jm map[string]any, k string) (map[string]any, error)

MapAtKey returns the requested key value as a JSON map (map[string]any).

func SliceAtKey

func SliceAtKey(jm map[string]any, k string) ([]any, error)

SliceAtKey returns the requested key value as a JSON slice ([]any).

func StringAtIndex

func StringAtIndex(js []any, idx int) (string, error)

StringAtIndex returns the slice value at the specified index as a string.

func StringAtKey

func StringAtKey(jm map[string]any, k string) (string, error)

StringAtKey returns the requested key value as a string.

func StringsAtKey

func StringsAtKey(jm map[string]any, k string) ([]string, error)

StringsAtKey returns the requested key value as a slice of string values.

func UnmarshalAtKey

func UnmarshalAtKey(jm map[string]any, k string, v any) error

UnmarshalAtKey unmarshals the bytes for a key value into the specified variable.

Types

type IndexOutOfBoundsError

type IndexOutOfBoundsError struct {
	ActualLen int
	// contains filtered or unexported fields
}

An IndexOutOfBoundsError is returned when the requested index is not valid.

func NewIndexOutOfBoundsError

func NewIndexOutOfBoundsError(idx, actualLen int) *IndexOutOfBoundsError

func (*IndexOutOfBoundsError) Error

func (e *IndexOutOfBoundsError) Error() string

type IndexTypeError

type IndexTypeError struct {
	// contains filtered or unexported fields
}

An IndexTypeError is the error that is returned when a value is requested for an index value in a slice and the value is not of the expected tpe.

func NewIndexTypeError

func NewIndexTypeError(index int, expectedType string, actual any) *IndexTypeError

func (*IndexTypeError) Error

func (e *IndexTypeError) Error() string

type KeyError

type KeyError struct {
	Err error
	// contains filtered or unexported fields
}

A KeyError wraps an error that occurs when requesting a key value.

func NewKeyError

func NewKeyError(k string, err error) *KeyError

func (*KeyError) Error

func (e *KeyError) Error() string

func (*KeyError) Unwrap

func (e *KeyError) Unwrap() error

type KeyTypeError

type KeyTypeError struct {
	// contains filtered or unexported fields
}

A KeyTypeError is the error that is returned by functions in this package when key is requested, it exists, but is not of the expected type.

func NewKeyTypeError

func NewKeyTypeError(key, expectedType string, actual any) *KeyTypeError

func (*KeyTypeError) Error

func (e *KeyTypeError) Error() string

type MissingKeyError

type MissingKeyError struct {
	// contains filtered or unexported fields
}

A MissingKeyError is the error that is returned by functions in this package when a key is requrested and is not found.

func NewMissingKeyError

func NewMissingKeyError(key string) *MissingKeyError

func (*MissingKeyError) Error

func (e *MissingKeyError) Error() string

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL