json

package
v0.9.0 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

Package json provides JSON utilities and wrappers around buger/jsonparser

Index

Constants

View Source
const (
	STRING = jsp.String
	NUMBER = jsp.Number
	OBJECT = jsp.Object
	ARRAY  = jsp.Array
	BOOL   = jsp.Boolean
	NULL   = jsp.Null
)

Variables

View Source
var (
	ErrValue = errors.New("invalid value")

	True  = []byte("true")
	False = []byte("false")
	Null  = []byte("null")
)

Functions

func Addr

func Addr(dst []byte, src netip.Addr) []byte

func ArrayEach

func ArrayEach(src []byte, cb func(key int, val []byte, typ Type) error) (reterr error)

ArrayEach calls cb for each *non-nil* value in the src array. If the callback returns or panics with an error, ArrayEach immediately returns it.

func Ascii added in v0.1.6

func Ascii(dst, src []byte) []byte

Ascii appends ASCII characters from src to JSON string in dst

func B added in v0.2.0

func B(str string) []byte

B returns byte slice from string, in an unsafe way

func Bool

func Bool(dst []byte, val bool) []byte

func Byte

func Byte(dst []byte, src byte) []byte

func Get

func Get(src []byte, path ...string) []byte

Get returns raw JSON value located at given key path, or nil if not found or error.

func GetBool

func GetBool(src []byte, path ...string) bool

GetBool returns true iff src JSON has a true value at given key path.

func Hex

func Hex(dst []byte, src []byte) []byte

func Int

func Int(dst []byte, src int) []byte

func ObjectEach

func ObjectEach(src []byte, cb func(key string, val []byte, typ Type) error) (reterr error)

ObjectEach calls cb for each non-null value in the src object. If the callback returns or panics with an error, ObjectEach immediately returns it.

func ObjectPaths added in v0.9.0

func ObjectPaths(src []byte, cb func(pid int, val []byte, typ Type) error, paths ...[]string) (reterr error)

ObjectPaths calls cb for each of the specified keys in the src object. If the callback returns or panics with an error, ObjectPaths immediately returns it.

func Prefix

func Prefix(dst []byte, src netip.Prefix) []byte

func Q

func Q(buf []byte) []byte

Q removes "double quotes" in buf, if present

func S

func S(buf []byte) string

S returns string from byte slice, in an unsafe way

func SQ

func SQ(buf []byte) string

SQ returns string from byte slice, unquoting if necessary

func Uint16

func Uint16(dst []byte, src uint16) []byte

func Uint32

func Uint32(dst []byte, src uint32) []byte

func UnAddr

func UnAddr(src []byte) (netip.Addr, error)

func UnBool

func UnBool(src []byte) (bool, error)

func UnByte

func UnByte(src []byte) (byte, error)

func UnHex

func UnHex(src []byte, dst []byte) ([]byte, error)

func UnInt

func UnInt(src []byte) (int, error)

func UnPrefix

func UnPrefix(src []byte) (netip.Prefix, error)

func UnUint16

func UnUint16(src []byte) (uint16, error)

func UnUint32

func UnUint32(src []byte) (uint32, error)

Types

type Type

type Type = jsp.ValueType

Jump to

Keyboard shortcuts

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