ejson

package module
v0.0.0-...-6d03bba Latest Latest
Warning

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

Go to latest
Published: Jan 13, 2025 License: ISC Imports: 13 Imported by: 20

README

go-ejson

Introduction

The EJSON library contains multiple utilities to work with JSON:

  • An implementation of RFC 6901 providing utilities to manipulate JSON pointers.
  • A validator to write extended validation code for the content of your JSON structures.

Usage

Refer to the Go package documentation for information about the API.

See the example programs for practical use cases.

Licensing

EJSON is open source software distributed under the ISC license.

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrInvalidPointerFormat = errors.New("invalid format")

Functions

func AsArray

func AsArray(v interface{}) []interface{}

func AsBoolean

func AsBoolean(v interface{}) bool

func AsNumber

func AsNumber(v interface{}) float64

func AsObject

func AsObject(v interface{}) map[string]interface{}

func AsString

func AsString(v interface{}) string

func ConvertUnmarshallingError

func ConvertUnmarshallingError(err error) error

func Equal

func Equal(v1, v2 interface{}) bool

func IsArray

func IsArray(v interface{}) bool

func IsBoolean

func IsBoolean(v interface{}) bool

func IsNull

func IsNull(v interface{}) bool

func IsNumber

func IsNumber(v interface{}) bool

func IsObject

func IsObject(v interface{}) bool

func IsString

func IsString(v interface{}) bool

func ObjectKeys

func ObjectKeys(v interface{}) []string

func ObjectValues

func ObjectValues(v interface{}) []interface{}

func Unmarshal

func Unmarshal(data []byte, dest interface{}) error

func UnmarshalDecoder

func UnmarshalDecoder(d *json.Decoder, dest interface{}) error

func UnmarshalReader

func UnmarshalReader(r io.Reader, dest interface{}) error

func Validate

func Validate(value interface{}) error

Types

type InvalidValueError

type InvalidValueError struct {
	Value interface{}
}

func (*InvalidValueError) Error

func (err *InvalidValueError) Error() string

type Pointer

type Pointer []string

func NewPointer

func NewPointer(tokens ...interface{}) Pointer

func (*Pointer) Append

func (p *Pointer) Append(tokens ...string)

func (Pointer) Child

func (p Pointer) Child(tokens ...interface{}) Pointer

func (Pointer) Find

func (p Pointer) Find(value interface{}) interface{}

func (Pointer) MarshalJSON

func (p Pointer) MarshalJSON() ([]byte, error)

func (*Pointer) MustParse

func (p *Pointer) MustParse(s string)

func (Pointer) Parent

func (p Pointer) Parent() Pointer

func (*Pointer) Parse

func (p *Pointer) Parse(s string) error

func (*Pointer) Prepend

func (p *Pointer) Prepend(tokens ...string)

func (Pointer) String

func (p Pointer) String() string

func (*Pointer) UnmarshalJSON

func (p *Pointer) UnmarshalJSON(data []byte) error

type Validatable

type Validatable interface {
	ValidateJSON(v *Validator)
}

type ValidationError

type ValidationError struct {
	Pointer Pointer `json:"pointer"`
	Code    string  `json:"code"`
	Message string  `json:"message"`
}

func (ValidationError) Error

func (err ValidationError) Error() string

type ValidationErrors

type ValidationErrors []*ValidationError

func (ValidationErrors) Error

func (errs ValidationErrors) Error() string

type Validator

type Validator struct {
	Pointer Pointer
	Errors  ValidationErrors
}

func NewValidator

func NewValidator() *Validator

func (*Validator) AddError

func (v *Validator) AddError(token interface{}, code, format string, args ...interface{})

func (*Validator) Check

func (v *Validator) Check(token interface{}, value bool, code, format string, args ...interface{}) bool

func (*Validator) CheckArrayLengthMax

func (v *Validator) CheckArrayLengthMax(token interface{}, value interface{}, max int) bool

func (*Validator) CheckArrayLengthMin

func (v *Validator) CheckArrayLengthMin(token interface{}, value interface{}, min int) bool

func (*Validator) CheckArrayLengthMinMax

func (v *Validator) CheckArrayLengthMinMax(token interface{}, value interface{}, min, max int) bool

func (*Validator) CheckArrayNotEmpty

func (v *Validator) CheckArrayNotEmpty(token interface{}, value interface{}) bool

func (*Validator) CheckDomainName

func (v *Validator) CheckDomainName(token any, s string)

func (*Validator) CheckEmailAddress

func (v *Validator) CheckEmailAddress(token any, s string)

func (*Validator) CheckFloatMax

func (v *Validator) CheckFloatMax(token interface{}, i, max float64) bool

func (*Validator) CheckFloatMin

func (v *Validator) CheckFloatMin(token interface{}, i, min float64) bool

func (*Validator) CheckFloatMinMax

func (v *Validator) CheckFloatMinMax(token interface{}, i, min, max float64) bool

func (*Validator) CheckInt64Max

func (v *Validator) CheckInt64Max(token interface{}, i, max int64) bool

func (*Validator) CheckInt64Min

func (v *Validator) CheckInt64Min(token interface{}, i, min int64) bool

func (*Validator) CheckInt64MinMax

func (v *Validator) CheckInt64MinMax(token interface{}, i, min, max int64) bool

func (*Validator) CheckIntMax

func (v *Validator) CheckIntMax(token interface{}, i int, max int) bool

func (*Validator) CheckIntMin

func (v *Validator) CheckIntMin(token interface{}, i int, min int) bool

func (*Validator) CheckIntMinMax

func (v *Validator) CheckIntMinMax(token interface{}, i int, min, max int) bool

func (*Validator) CheckNetworkAddress

func (v *Validator) CheckNetworkAddress(token any, s string)

func (*Validator) CheckObject

func (v *Validator) CheckObject(token interface{}, value interface{}) bool

func (*Validator) CheckObjectArray

func (v *Validator) CheckObjectArray(token interface{}, value interface{}) bool

func (*Validator) CheckObjectMap

func (v *Validator) CheckObjectMap(token interface{}, value interface{}) bool

func (*Validator) CheckOptionalObject

func (v *Validator) CheckOptionalObject(token interface{}, value interface{}) bool

func (*Validator) CheckStringLengthMax

func (v *Validator) CheckStringLengthMax(token interface{}, s string, max int) bool

func (*Validator) CheckStringLengthMin

func (v *Validator) CheckStringLengthMin(token interface{}, s string, min int) bool

func (*Validator) CheckStringLengthMinMax

func (v *Validator) CheckStringLengthMinMax(token interface{}, s string, min, max int) bool

func (*Validator) CheckStringMatch

func (v *Validator) CheckStringMatch(token interface{}, s string, re *regexp.Regexp) bool

func (*Validator) CheckStringMatch2

func (v *Validator) CheckStringMatch2(token interface{}, s string, re *regexp.Regexp, code, format string, args ...interface{}) bool

func (*Validator) CheckStringNotEmpty

func (v *Validator) CheckStringNotEmpty(token interface{}, s string) bool

func (*Validator) CheckStringURI

func (v *Validator) CheckStringURI(token interface{}, s string) bool

func (*Validator) CheckStringValue

func (v *Validator) CheckStringValue(token interface{}, value interface{}, values interface{}) bool

func (*Validator) CheckUUID

func (v *Validator) CheckUUID(token interface{}, value interface{}) bool

func (*Validator) Error

func (v *Validator) Error() error

func (*Validator) Pop

func (v *Validator) Pop()

func (*Validator) Push

func (v *Validator) Push(token interface{})

func (*Validator) WithChild

func (v *Validator) WithChild(token interface{}, fn func())

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

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