Documentation
¶
Index ¶
- func Parse(in []byte) iter.Seq2[Item, error]
- func Reconstruct(in []byte) ([]byte, error)
- func Scan(in []byte) iter.Seq2[RawToken, error]
- func ShouldAddComma(lastToken, nextToken TokenType) bool
- type Item
- func (x Item) Format(f fmt.State, c rune)
- func (x Item) GetAltPathString() string
- func (x Item) GetPath() Path
- func (x Item) GetPathString() string
- func (x Item) GetRawPath() RawPath
- func (x Item) GetTokenValue() (any, error)
- func (x Item) GetValue() (any, error)
- func (x Item) IsArrayValue() bool
- func (x Item) IsObjectValue() bool
- func (x Item) String() string
- type Path
- type PathItem
- type RawPath
- type RawToken
- func (r RawToken) Bytes() []byte
- func (r RawToken) GetBool() (bool, error)
- func (r RawToken) GetNumber() (float64, error)
- func (r RawToken) GetString() (string, error)
- func (r RawToken) GetValue() (any, error)
- func (r RawToken) IsClose() bool
- func (r RawToken) IsOpen() bool
- func (r RawToken) IsValue() bool
- func (r RawToken) IsZero() bool
- func (r RawToken) Raw() []byte
- func (r RawToken) String() string
- func (r RawToken) Type() TokenType
- type TokenType
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Reconstruct ¶
Reconstruct is an example of how to reconstruct a JSON from Parse().
func ShouldAddComma ¶
Types ¶
type Item ¶
type Item struct {
Level int // level of indentation
Index int // index in the parent array or object
Key RawToken // optional object "key"
Token RawToken // [ or { or } or ] or , or value
// contains filtered or unexported fields
}
func (Item) GetAltPathString ¶
GetAltPathString returns the path of the item as a string `[0].key[1]`.
func (Item) GetPath ¶
GetPath returns the path of the item as a slice of values. The values are the keys of objects (string) and the indexes of arrays (int).
func (Item) GetPathString ¶
GetPathString returns the path of the item as a string "0.key.1".
func (Item) GetRawPath ¶
GetRawPath returns the path of the item as a slice of PathItem. IMPORTANT: The result slice should not be modified.
func (Item) GetTokenValue ¶
func (Item) IsArrayValue ¶
func (Item) IsObjectValue ¶
type Path ¶
type Path []any
Path is a slice of values. The values are the keys of objects (string) and the indexes of arrays (int).
type PathItem ¶
func (PathItem) Format ¶
Format formats the path item as a string. Use "%+v" to format as "[0]" for array, ".key" for object.
type RawPath ¶
type RawPath []PathItem
type RawToken ¶
type RawToken struct {
// contains filtered or unexported fields
}
RawToken represents a raw token from the scanner.
func (RawToken) GetString ¶
GetString returns the unquoted string value of the token. https://datatracker.ietf.org/doc/html/rfc8259#section-7
type TokenType ¶
type TokenType byte
TokenType represents the type of a JSON token.
const ( TokenNull TokenType = 'n' TokenTrue TokenType = 't' TokenFalse TokenType = 'f' TokenNumber TokenType = '0' TokenString TokenType = '"' TokenObjectStart TokenType = '{' TokenObjectEnd TokenType = '}' TokenArrayStart TokenType = '[' TokenArrayEnd TokenType = ']' TokenComma TokenType = ',' TokenColon TokenType = ':' )