jparser

package
v0.0.5 Latest Latest
Warning

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

Go to latest
Published: Dec 14, 2020 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package jparser provides helper methods to parse JSON from stream.

Index

Constants

View Source
const (
	// DelimObjectStart contains json object '{' start delimiter.
	DelimObjectStart = "{"
	// DelimObjectEnd contains json object '}' start delimiter.
	DelimObjectEnd = "}"
	// DelimArrayStart contains json array '[' start delimiter.
	DelimArrayStart = "["
	// DelimArrayEnd contains json array '}' end delimiter.
	DelimArrayEnd = "]"
)

Variables

This section is empty.

Functions

func CheckArrayStart

func CheckArrayStart(d *json.Decoder, desc string) error

CheckArrayStart checks whether next token is '[' in JSON byte stream.

func CheckEOF

func CheckEOF(d *json.Decoder) error

CheckEOF checks EOF of the JSON byte stream.

func CheckObjectArrayStart

func CheckObjectArrayStart(d *json.Decoder, desc string) (bool, error)

CheckObjectArrayStart checks whether next token is '[' or "{" in JSON byte stream. It returns true if it is "{" if there wasn't any error.

func CheckObjectStart

func CheckObjectStart(d *json.Decoder, desc string) error

CheckObjectStart checks whether next token is '{' in JSON byte stream.

func CheckRootArrayStart

func CheckRootArrayStart(d *json.Decoder) (bool, error)

CheckRootArrayStart checks whether JSON byte stream starts with '['

func CheckRootObjectStart

func CheckRootObjectStart(d *json.Decoder) (bool, error)

CheckRootObjectStart checks whether JSON byte stream starts with '{'

func GetArray

func GetArray(d *json.Decoder, desc string) ([]interface{}, error)

GetArray unmarshals whole array from JSON byte stream to an []interface{}. []interface{} item is an array of Pairs or primitive value or []interface{}.

func GetBoolean

func GetBoolean(d *json.Decoder, desc string) (bool, error)

GetBoolean unmarshals boolean value from JSON byte stream.

func GetNumber

func GetNumber(d *json.Decoder, desc string) (float64, error)

GetNumber unmarshals number from JSON byte stream.

func GetString

func GetString(d *json.Decoder, desc string) (string, error)

GetString unmarshals string value from JSON byte stream.

func GetStringSequence

func GetStringSequence(d *json.Decoder, f func(idx int, s string) error, desc string) error

GetStringSequence iterates over object keys or string array items in JSON byte stream.

func GetStringSequenceFromArray

func GetStringSequenceFromArray(d *json.Decoder, f func(idx int, s string) error, desc string) error

GetStringSequenceFromArray iterates over string array items in JSON byte stream.

func GetStringSequenceFromObject

func GetStringSequenceFromObject(d *json.Decoder, f func(idx int, s string) error, desc string) error

GetStringSequenceFromObject iterates over object keys in JSON byte stream.

func GetUndefined

func GetUndefined(d *json.Decoder, desc string) (interface{}, error)

GetUndefined unmarshals whole part of JSON byte stream. Part is an object or an array or primitive value. It returns array of Pairs or primitive value or []interface{}.

func SkipArray

func SkipArray(d *json.Decoder, desc string) error

SkipArray skips array in JSON byte stream.

func SkipObject

func SkipObject(d *json.Decoder, desc string) error

SkipObject skips object in JSON byte stream.

func SkipValue

func SkipValue(d *json.Decoder, desc string) error

SkipValue skips object or array in JSON byte stream.

func UnmarshalObject

func UnmarshalObject(d *json.Decoder, u func(key string, d *json.Decoder) error, desc string) error

UnmarshalObject sequentially unmarshals object from JSON byte stream.

func UnmarshalObjectArray

func UnmarshalObjectArray(d *json.Decoder, u func(idx int, d *json.Decoder) error, desc string) error

UnmarshalObjectArray sequentially unmarshals array from JSON byte stream.

Types

type Pair

type Pair struct {
	K string
	V interface{}
}

Pair represents unmarshalled part of JSON byte stream. Value is an array of Pairs or primitive value or []interface{}.

func GetObject

func GetObject(d *json.Decoder, desc string) ([]Pair, error)

GetObject unmarshals whole object from JSON byte stream to a list of Piars.

Jump to

Keyboard shortcuts

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