zjson

package
v0.1.55 Latest Latest
Warning

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

Go to latest
Published: Sep 7, 2020 License: MIT Imports: 15 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}
	Maches     = []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, iterator 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 *StSetOptions) ([]byte, error)

func SetModifiersState

func SetModifiersState(b bool)

func SetOptions

func SetOptions(json, path string, value interface{},
	opts *StSetOptions) (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 *StSetOptions) ([]byte, error)

func SetRawOptions

func SetRawOptions(json, path, value string, opts *StSetOptions) (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 UnmarshalValidationEnabled

func UnmarshalValidationEnabled(enabled bool)

func Valid

func Valid(json string) (ok bool)

func ValidBytes

func ValidBytes(json []byte) bool

Types

type Map

type Map map[string]string

type Res

type Res struct {
	Type  Type
	Raw   string
	Str   string
	Num   float64
	Index int
}

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) Exists

func (r Res) Exists() bool

func (Res) Float

func (r Res) Float() float64

func (Res) ForEach

func (r Res) ForEach(iterator 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() map[string]Res

func (Res) String

func (r Res) String() string

func (Res) Time

func (r Res) Time(format ...string) 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 {
	Width    int
	Prefix   string
	Indent   string
	SortKeys bool
}

type StSetOptions

type StSetOptions struct {
	Optimistic     bool
	ReplaceInPlace 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