dirtyjson

package
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Array

type Array []any

Array means array of anything.

func (*Array) UnmarshalJSON

func (v *Array) UnmarshalJSON(data []byte) error

UnmarshalJSON converts []byte into an Array.

type Bool

type Bool bool

Bool means a boolean value.

func (*Bool) UnmarshalJSON

func (v *Bool) UnmarshalJSON(data []byte) error

UnmarshalJSON converts []byte into a Bool.

type CleanDecoder

type CleanDecoder interface {
	Token() (Token, error)
	More() bool
	Decode(v any) error
}

CleanDecoder is an interface that stands for the part of `*json.Decoder` that is required in dirty decoding. It also allows us to switch from std `json.Decoder` to other faster (std-compatible) decoders.

type Color

type Color int

Color means the color of dirty unmarshalling.

const (
	// ColorGreen means 100% clean unmarshalling.
	// Data could be unmarshalled directly into the target clean struct.
	ColorGreen Color = iota

	// ColorYellow means successful (lossless) unmarshalling via dirty schema.
	// At least one dirty concept was used. See `Warnings` to list them.
	ColorYellow

	// ColorRed means partially successful (lossy) unmarshalling via dirty schema.
	// At least one field was lost during unmarshalling. See `Errors` to list them.
	ColorRed
)

type Date

type Date time.Time

Date means a date (time pointing to a specific day).

func (*Date) UnmarshalJSON

func (v *Date) UnmarshalJSON(data []byte) error

UnmarshalJSON converts []byte into a Date.

type DateTime

type DateTime time.Time

DateTime means a time (time pointing to a specific moment).

func (*DateTime) UnmarshalJSON

func (v *DateTime) UnmarshalJSON(data []byte) error

UnmarshalJSON converts []byte into a Date.

type Decoder

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

Decoder is the dirty decoder, it wraps the "clean" decoder.

func NewDecoder

func NewDecoder(r io.Reader) *Decoder

NewDecoder creates a new dirty decoder.

func (*Decoder) Decode

func (dec *Decoder) Decode(val any) error

Decode decodes the given value respecting dirty schema if possible.

func (*Decoder) More

func (dec *Decoder) More() bool

func (*Decoder) Token

func (dec *Decoder) Token() (Token, error)

type Dirtyable

type Dirtyable interface {
	Dirty() any
}

Dirtyable is used as a way to link a clean model with a dirty model.

type Disabled

type Disabled struct{}

Disabled is an atom struct that that remains a syntactically valid dirty model but disables dirty unmarshalling. You can easily switch from `dirty.Enabled` to `dirty.Disabled` keeping all models and interfaces working (falling back to standard (clean) json.Unmarshal).

type Enabled

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

Enabled is a struct atom that enables dirty unmarshalling for the struct where it's embedded.

type Integer

type Integer int64

Integer means an Integer number.

func (*Integer) UnmarshalJSON

func (v *Integer) UnmarshalJSON(data []byte) error

UnmarshalJSON converts []byte into an Integer.

type Number

type Number float64

Number means any number (Integer, Float, Scientific, etc.)

func (*Number) UnmarshalJSON

func (v *Number) UnmarshalJSON(data []byte) error

UnmarshalJSON converts []byte into a Number.

type Object

type Object map[string]any

Object is a JSON-like map (string->any).

func (*Object) UnmarshalJSON

func (v *Object) UnmarshalJSON(data []byte) error

UnmarshalJSON converts []byte into an Object.

type Result

type Result[D any] struct {
	// contains filtered or unexported fields
}

Result stores the result of unmarshalling (as a filled Dirty model).

func (*Result[D]) Color

func (r *Result[D]) Color() Color

func (*Result[D]) Errors

func (r *Result[D]) Errors() []any

func (*Result[D]) Result

func (r *Result[D]) Result() *D

func (*Result[D]) Warnings

func (r *Result[D]) Warnings() []any

type String

type String string

String means simply a string.

func (*String) UnmarshalJSON

func (v *String) UnmarshalJSON(data []byte) error

UnmarshalJSON converts []byte into a Bool.

type Time

type Time time.Time

Time means a given moment within a day (day is not specified in the source value).

func (*Time) UnmarshalJSON

func (v *Time) UnmarshalJSON(data []byte) error

UnmarshalJSON converts []byte into a Date.

type Token

type Token = json.Token

Token is needed for the `CleanDecoder` interface.

Jump to

Keyboard shortcuts

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