Documentation ¶
Overview ¶
Package jsonmuncher is a very performant streaming JSON parser.
Index ¶
- Variables
- type ErrTypeMismatch
- type ErrUnexpectedChar
- type JsonStatus
- type JsonType
- type JsonValue
- func (data *JsonValue) Close() error
- func (data *JsonValue) Compare(vals ...string) (string, bool, error)
- func (data *JsonValue) FindKey(keys ...string) (string, JsonValue, bool, error)
- func (data *JsonValue) NextKey() (JsonValue, error)
- func (data *JsonValue) NextValue() (JsonValue, error)
- func (data *JsonValue) Read(b []byte) (int, error)
- func (data *JsonValue) ValueBool() (bool, error)
- func (data *JsonValue) ValueNum() (float64, error)
Constants ¶
This section is empty.
Variables ¶
var EndOfValue = errors.New("End of value reached")
EndOfValue denotes that the end of an object or array has already been reached, and no new elements can be read. This is returned by the NextKey() and NextValue() functions.
var ErrIncomplete = errors.New("Status incomplete denotes failed read")
ErrIncomplete is returned when a call is made to a value with an "Incomplete" status, meaning a read error had occurred during a previous operation.
var ErrNoParamsSpecified = errors.New("At least one argument should be provided")
ErrNoParamsSpecified is returned from the Compare() and FindKey() functions when no arguments are passed. These variadic functions expect at least one argument.
var ErrWorkingChild = errors.New("Unable to consume when child element is partially read")
ErrWorkingChild is returned when NextKey(), NextValue(), or Close() is called on an object or array, but one of its elements is only partially read. The child element must be fully read or closed first.
Functions ¶
This section is empty.
Types ¶
type ErrTypeMismatch ¶
ErrTypeMismatch is returned when a JsonValue method specific to a particular JSON type is called on a different JSON type. For example, ValueNum() will return this error if called on any JsonValue that isn't a Number.
func (ErrTypeMismatch) Error ¶
func (e ErrTypeMismatch) Error() string
Error implements error for ErrTypeMismatch.
type ErrUnexpectedChar ¶
type ErrUnexpectedChar struct { Offset uint64 ProvidedEOF bool Provided byte Expected []byte CustomMsg string }
ErrUnexpectedChar is returned whenever a syntactic parse error is encountered: an illegal character or an unexpected EOF.
func (ErrUnexpectedChar) Error ¶
func (e ErrUnexpectedChar) Error() string
Error implements error for ErrUnexpectedChar.
type JsonStatus ¶
type JsonStatus byte
JsonStatus represents the current read status of a JsonValue.
const ( // Incomplete means there was a read or parse error while parsing the value. Incomplete JsonStatus = iota // Working means the value is currently in the process of being parsed. Working // Complete means the value has been parsed successfully in its entirety. Complete )
type JsonType ¶
type JsonType byte
JsonType represents the data type of a JsonValue.
const ( // Null values are always 'null'. Null JsonType = iota // Bool values are 'true' or 'false'. Bool // Number values are double-precision floating point numbers. Number // String values are unicode strings. String // Array values are ordered collections of arbitrary JSON values. Array // Object values are maps from strings to arbitrary JSON values. Object )
type JsonValue ¶
type JsonValue struct { // Type is the data type of this value. Type JsonType // Status is the read status of this value. Status JsonStatus // contains filtered or unexported fields }
JsonValue represents a JSON value. This is the primary structure used in this library.
func Parse ¶
Parse takes an io.Reader and begins to parse from it, returning a JsonValue. This function also takes a size (in bytes) to use when creating the read buffer.
func (*JsonValue) Close ¶
Close implements the io.Closer interface for JsonValues. Closing a JsonValue discards the remainder of that value from the stream. This is a fast way to ignore unimportant parts of the input to reach useful information.
func (*JsonValue) Compare ¶
Compare is a helper function, designed to read a String value and compare it against one or more arguments. If the String value matches none of the arguments, false is returned. Otherwise, true is returned along with the matched string.
func (*JsonValue) FindKey ¶
FindKey is a helper function, designed to find a specific value in an Object. It reads the object until it finds the first key that matches one of the provided arguments. If no keys match, false is returned. Otherwise, true is returned along with the matched string and the value associated with the matched key. Note that this will discard everything in the stream prior to the matched key/value pair.
func (*JsonValue) NextKey ¶
NextKey reads the next key from an Object, and returns it as a JsonValue. If the next part of the Object to parse is a value, that value is discarded, and the following key is returned. If the end of the Object is found, an EndOfValue error is returned.
func (*JsonValue) NextValue ¶
NextValue reads the next value from an Object or Array, and returns it as a JsonValue. If this is used on an Object, and the next part of the Object to parse is a key, that key is discarded and the corresponding value is returned. If the end of the Object or Array is found, an EndOfValue error is returned.
func (*JsonValue) Read ¶
Read implements the io.Reader interface for JsonValues (specifically, String values). Reading from this interface provides the value of the string.