es_json

package
v0.6.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

View Source
const (
	TagPathName          = "path"
	TagPathValueRequired = "required"
	PathArrayFirst       = "0"
)

Variables

View Source
var (
	ErrorInvalidJSONFormat    = errors.New("invalid json format")
	ErrorNotFound             = errors.New("data not found for the path")
	ErrorMissingRequired      = errors.New("missing required field")
	ErrorUnsupportedFieldType = errors.New("unsupported field type")
	ErrorNotAnArray           = errors.New("data is not an array")
)

Functions

func ToJsonString

func ToJsonString(v interface{}) string

func Validate

func Validate(j []byte) bool

func ValidateString

func ValidateString(j string) bool

Types

type Json

type Json interface {
	// Raw JSON message
	Raw() json.RawMessage

	// Raw string
	RawString() string

	// True if the instance is null
	IsNull() bool

	// Returns an array value and true if this instance is an array.
	Array() (v []Json, t bool)

	// Run each entries
	ArrayEach(f func(e Json) error) error

	// Returns an object value and true if this instance is an object.
	Object() (v map[string]Json, t bool)

	// Returns an boolean value and true if this instance is true/false.
	Bool() (v bool, t bool)

	// Returns a number value and true if this instance is a number.
	Number() (v es_number.Number, t bool)

	// Returns a string value and true if this instance is a string.
	String() (v string, t bool)

	// Parse model with given type.
	Model(v interface{}) (err error)

	// Find value under the path. Returns nil & false if not found.
	Find(path string) (j Json, found bool)

	// Find then Model.
	FindModel(path string, v interface{}) (err error)

	// Find an array
	FindArray(path string) (v []Json, t bool)

	// Find an array
	FindArrayEach(path string, f func(e Json) error) error

	// Find an object
	FindObject(path string) (v map[string]Json, t bool)

	// Find Bool
	FindBool(path string) (v bool, t bool)

	// Returns a number value and true if this instance is a number.
	FindNumber(path string) (v es_number.Number, t bool)

	// Returns a string value and true if this instance is a string.
	FindString(path string) (v string, t bool)
}

Wrapper of gjson

func MustParse

func MustParse(j []byte) Json

func MustParseString

func MustParseString(j string) Json

func Null

func Null() Json

func Parse

func Parse(j []byte) (Json, error)

func ParseString

func ParseString(j string) (Json, error)

Jump to

Keyboard shortcuts

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