jsonx

package
v0.0.0-...-419c0c3 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2025 License: MIT Imports: 16 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Nanosecond  Duration = 1
	Microsecond          = 1000 * Nanosecond
	Millisecond          = 1000 * Microsecond
	Second               = 1000 * Millisecond
	Minute               = 60 * Second
	Hour                 = 60 * Minute
)

Variables

View Source
var (
	Unmarshal = json.Unmarshal
	Marshal   = json.Marshal
)

Functions

func Decode

func Decode(r io.Reader, v any, limitSize ...int64) error

func FieldIs

func FieldIs(field, value string) func(item Raw) bool

func KeyIs

func KeyIs(field string) func(item Raw) string

func MarshalToFile

func MarshalToFile(file string, v any) error

func UnmarshalFromFile

func UnmarshalFromFile(file string, v any) error

Types

type Duration

type Duration time.Duration

func (Duration) MarshalJSON

func (d Duration) MarshalJSON() ([]byte, error)

func (*Duration) UnmarshalJSON

func (d *Duration) UnmarshalJSON(data []byte) (err error)

func (Duration) Value

func (d Duration) Value() time.Duration

type Ints

type Ints = List[int64]

type List

type List[T any] []T

func (List[T]) MarshalJSON

func (s List[T]) MarshalJSON() ([]byte, error)

func (*List[T]) UnmarshalJSON

func (s *List[T]) UnmarshalJSON(data []byte) (err error)

type Raw

type Raw string

Raw 原始json数据, 封装了一些常用便捷的操作

func From

func From(v any) Raw

func FromE

func FromE(v any) (Raw, error)

func Get

func Get[T ~string | ~[]byte](src T, key ...string) Raw

func Load

func Load(file string) Raw

func LoadE

func LoadE(file string) (Raw, error)

func LoadYaml

func LoadYaml(file string) Raw

func LoadYamlE

func LoadYamlE(file string) (Raw, error)

func New

func New(key string, value any) Raw

func ParseYaml

func ParseYaml(yaml []byte) Raw

func ParseYamlE

func ParseYamlE(yaml []byte) (Raw, error)

func Read

func Read(r io.Reader) (Raw, error)

func (Raw) Del

func (r Raw) Del(keys ...string) Raw

如果失败则不做更改

func (Raw) Exists

func (r Raw) Exists(key string) bool

func (Raw) Get

func (r Raw) Get(key string) Raw

func (Raw) GetBool

func (r Raw) GetBool(key string, def ...bool) bool

GetBool 获取bool值, 如果不存在, 则返回def

func (Raw) GetBools

func (r Raw) GetBools(key string) []bool

func (Raw) GetDuration

func (r Raw) GetDuration(key string) time.Duration

func (Raw) GetFloat

func (r Raw) GetFloat(key string) float64

func (Raw) GetFloats

func (r Raw) GetFloats(key string) []float64

func (Raw) GetInt

func (r Raw) GetInt(key string) int64

func (Raw) GetInts

func (r Raw) GetInts(key string) []int64

func (Raw) GetRet

func (r Raw) GetRet(key string) Result

func (Raw) GetString

func (r Raw) GetString(key string) string

func (Raw) GetStrings

func (r Raw) GetStrings(key string) []string

func (Raw) GetTime

func (r Raw) GetTime(key string) (dst time.Time)

func (Raw) Gets

func (r Raw) Gets(key string) []Raw

func (Raw) Index

func (r Raw) Index(key string) int

func (Raw) Indexes

func (r Raw) Indexes(key string) []int

func (Raw) IsEmpty

func (r Raw) IsEmpty() bool

func (Raw) Map

func (r Raw) Map(key string) (out map[string]Raw)

func (Raw) MarshalJSON

func (r Raw) MarshalJSON() ([]byte, error)

func (Raw) Pretty

func (r Raw) Pretty() Raw

func (Raw) Save

func (r Raw) Save(file string) error

func (Raw) Set

func (r Raw) Set(key string, value any) Raw

如果失败则不做更改

func (Raw) String

func (r Raw) String() string

func (Raw) Ugly

func (r Raw) Ugly() Raw

func (Raw) Unmarshal

func (r Raw) Unmarshal(obj any) error

func (*Raw) UnmarshalJSON

func (r *Raw) UnmarshalJSON(bytes []byte) error

func (Raw) WriteTo

func (r Raw) WriteTo(w io.Writer) (int64, error)

type Result

type Result = gjson.Result

type Strings

type Strings = List[string]

Jump to

Keyboard shortcuts

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