zjson

package
v1.7.12 Latest Latest
Warning

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

Go to latest
Published: Apr 27, 2024 License: MIT Imports: 17 Imported by: 9

Documentation

Overview

Package zjson json data read and write operations

Index

Constants

This section is empty.

Variables

View Source
var (
	DefOptions = &StFormatOptions{Width: 80, Prefix: "", Indent: "  ", SortKeys: false}
	Matches    = []Map{
		{"start": "//", "end": "\n"},
		{"start": "/*", "end": "*/"},
	}
)
View Source
var (
	ErrNoChange              = errors.New("no change")
	ErrPathEmpty             = errors.New("path cannot be empty")
	ErrInvalidJSON           = errors.New("invalid json")
	ErrNotAllowedWildcard    = errors.New("wildcard characters not allowed in path")
	ErrNotAllowedArrayAccess = errors.New("array access character not allowed in path")
	ErrTypeError             = errors.New("json must be an object or array")
)

Functions

func AddModifier

func AddModifier(name string, fn func(json, arg string) string)

func Delete

func Delete(json, path string) (string, error)

func DeleteBytes

func DeleteBytes(json []byte, path string) ([]byte, error)

func Discard

func Discard(json string) (string, error)

func ForEachLine

func ForEachLine(json string, fn func(line *Res) bool)

func Format

func Format(json []byte) []byte

func FormatOptions

func FormatOptions(json []byte, opts *StFormatOptions) []byte

func Marshal

func Marshal(json interface{}) ([]byte, error)

func ModifierExists

func ModifierExists(name string) bool

func ModifiersState

func ModifiersState() bool

func Set

func Set(json, path string, value interface{}) (string, error)

func SetBytes

func SetBytes(json []byte, path string, value interface{}) ([]byte, error)

func SetBytesOptions

func SetBytesOptions(json []byte, path string, value interface{},
	opts *Options) ([]byte, error)

func SetModifiersState

func SetModifiersState(b bool)

func SetOptions

func SetOptions(json, path string, value interface{},
	opts *Options) (string, error)

func SetRaw

func SetRaw(json, path, value string) (string, error)

func SetRawBytes

func SetRawBytes(json []byte, path string, value []byte) ([]byte, error)

func SetRawBytesOptions

func SetRawBytesOptions(json []byte, path string, value []byte,
	opts *Options) ([]byte, error)

func SetRawOptions

func SetRawOptions(json, path, value string, opts *Options) (string, error)

func Stringify

func Stringify(value interface{}) (json string)

func Ugly

func Ugly(json []byte) []byte

func Unmarshal

func Unmarshal(json, v interface{}) error

func Valid

func Valid(json string) (ok bool)

func ValidBytes

func ValidBytes(json []byte) bool

Types

type Map

type Map map[string]string

type Options added in v1.1.13

type Options struct {
	Optimistic     bool
	ReplaceInPlace bool
}

type Res

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

func Get

func Get(json, path string) *Res

func GetBytes

func GetBytes(json []byte, path string) *Res

func GetMultiple

func GetMultiple(json string, path ...string) []*Res

func GetMultipleBytes

func GetMultipleBytes(json []byte, path ...string) []*Res

func Parse

func Parse(json string) *Res

func ParseBytes

func ParseBytes(json []byte) *Res

func (*Res) Array

func (r *Res) Array() []*Res

func (*Res) Bool

func (r *Res) Bool() bool

func (*Res) Bytes added in v1.4.0

func (r *Res) Bytes() []byte

func (*Res) Delete added in v1.4.0

func (r *Res) Delete(path string) (err error)

func (*Res) Exists

func (r *Res) Exists() bool

func (*Res) Filter added in v1.4.0

func (r *Res) Filter(fn func(key, value *Res) bool) *Res

func (*Res) Float

func (r *Res) Float() float64

func (*Res) ForEach

func (r *Res) ForEach(fn func(key, value *Res) bool)

func (*Res) Get

func (r *Res) Get(path string) *Res

func (*Res) Int

func (r *Res) Int() int

func (*Res) IsArray

func (r *Res) IsArray() bool

func (*Res) IsObject

func (r *Res) IsObject() bool

func (*Res) Map

func (r *Res) Map() ztype.Map

func (*Res) MapKeys added in v1.2.0

func (r *Res) MapKeys(exclude ...string) (keys []string)

func (*Res) MapRes added in v1.6.4

func (r *Res) MapRes() map[string]*Res

func (*Res) Maps added in v1.6.4

func (r *Res) Maps() ztype.Maps

func (*Res) MatchKeys added in v1.4.0

func (r *Res) MatchKeys(keys []string) *Res

func (*Res) Raw

func (r *Res) Raw() string

func (*Res) Set added in v1.4.0

func (r *Res) Set(path string, value interface{}) (err error)

func (*Res) Slice added in v1.4.4

func (r *Res) Slice() ztype.SliceType

func (*Res) SliceInt added in v1.7.0

func (r *Res) SliceInt() []int

func (*Res) SliceString added in v1.7.0

func (r *Res) SliceString() []string

func (*Res) String

func (r *Res) String() string

func (*Res) Time

func (r *Res) Time(format ...string) (t time.Time)

func (*Res) Uint

func (r *Res) Uint() uint

func (*Res) Unmarshal

func (r *Res) Unmarshal(v interface{}) error

func (*Res) Value

func (r *Res) Value() interface{}

type StFormatOptions

type StFormatOptions struct {
	Prefix   string
	Indent   string
	Width    int
	SortKeys bool
}

type Type

type Type int
const (
	Null Type = iota
	False
	Number
	String
	True
	JSON
)

func (Type) String

func (t Type) String() string

Jump to

Keyboard shortcuts

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