jester

package module
v0.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 27, 2025 License: MIT Imports: 7 Imported by: 0

README

Jester 🎭

A lightweight JSON handling library in Go. Built from github.com/bitly/go-simplejson.

Why?

  • Uses github.com/goccy/go-json instead of encoding/json.
  • Get() supports string as well as int keys to index maps and slices in one call.
  • Added Len() func to get the length of the underlying data.
  • Added Iterator() func to easily iterate over slices and arrays.
  • I guess that's all.

Installation

go get github.com/lb-selfbot/go-jester

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrTypeMismatch = errors.New("jester: type assertion failed (type mismatch)")

Functions

This section is empty.

Types

type Data

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

func New

func New(data any) *Data

New creates a new Data instance with an empty map.

func NewEmpty

func NewEmpty() *Data

NewEmpty creates a new Data instance with an empty map.

func NewJson

func NewJson(data []byte) (d *Data, err error)

NewJson creates a new Data instance from JSON data.

func NewReader

func NewReader(r io.Reader) (d *Data, err error)

NewReader creates a new Data instance from an io.Reader.

func (*Data) Bool

func (d *Data) Bool() (bool, error)

Bool returns the underlying data as a bool.

func (*Data) Bytes

func (d *Data) Bytes() ([]byte, error)

Bytes returns the underlying data as a []byte.

func (*Data) Delete

func (d *Data) Delete(key string)

Delete deletes a key from the data structure.

func (*Data) Float64

func (d *Data) Float64() (float64, error)

Float64 returns the underlying data as a float64.

func (*Data) Get

func (d *Data) Get(keys ...any) *Data

Get retrieves a value from the data structure at the specified path.

func (*Data) Int

func (d *Data) Int() (int, error)

Int returns the underlying data as an int.

func (*Data) Int64

func (d *Data) Int64() (int64, error)

Int64 returns the underlying data as an int64.

func (*Data) Interface

func (d *Data) Interface() any

Interface returns the underlying data.

func (*Data) Iterator added in v0.3.0

func (d *Data) Iterator() iter.Seq[*Data]

Iterator returns an iterator for the underlying data.

func (*Data) Len added in v0.2.0

func (d *Data) Len() int

Len returns the length of the underlying data.

func (*Data) Map

func (d *Data) Map() (map[string]any, error)

Map returns the underlying data as a map[string]any.

func (*Data) MarshalJSON

func (d *Data) MarshalJSON() ([]byte, error)

MarshalJSON implements the json.Marshaler interface.

func (*Data) MustBool

func (d *Data) MustBool(args ...bool) bool

MustBool returns the underlying data as a bool with optional default value.

func (*Data) MustBytes

func (d *Data) MustBytes(args ...[]byte) []byte

MustBytes returns the underlying data as a []byte with optional default value.

func (*Data) MustFloat64

func (d *Data) MustFloat64(args ...float64) float64

MustFloat64 returns the underlying data as a float64 with optional default value.

func (*Data) MustInt

func (d *Data) MustInt(args ...int) int

MustInt returns the underlying data as an int with optional default value.

func (*Data) MustInt64

func (d *Data) MustInt64(args ...int64) int64

MustInt64 returns the underlying data as an int64 with optional default value.

func (*Data) MustMap

func (d *Data) MustMap(args ...map[string]any) map[string]any

MustMap returns the underlying data as a map[string]any with optional default value.

func (*Data) MustSlice

func (d *Data) MustSlice(args ...[]any) []any

MustSlice returns the underlying data as a []any with optional default value.

func (*Data) MustString

func (d *Data) MustString(args ...string) string

MustString returns the underlying data as a string with optional default value.

func (*Data) MustStringSlice

func (d *Data) MustStringSlice(args ...[]string) []string

MustStringSlice returns the underlying data as a []string with optional default value.

func (*Data) MustUint64

func (d *Data) MustUint64(args ...uint64) uint64

MustUint64 returns the underlying data as a uint64 with optional default value.

func (*Data) Set

func (d *Data) Set(key string, val any)

Set modifies the data structure by setting the value for the specified key.

func (*Data) SetPath

func (d *Data) SetPath(branch []any, val any)

SetPath modifies the data structure by setting the value for the specified path.

func (*Data) Slice

func (d *Data) Slice() ([]any, error)

Slice returns the underlying data as a []any.

func (*Data) String

func (d *Data) String() (string, error)

String returns the underlying data as a string.

func (*Data) StringSlice

func (d *Data) StringSlice() ([]string, error)

StringSlice returns the underlying data as a []string.

func (*Data) Uint64

func (d *Data) Uint64() (uint64, error)

Uint64 returns the underlying data as a uint64.

func (*Data) UnmarshalJSON

func (d *Data) UnmarshalJSON(data []byte) error

UnmarshalJSON implements the json.Unmarshaler interface.

Jump to

Keyboard shortcuts

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