Documentation ¶
Overview ¶
Package json is a JSON parser following the specifications at http://json.org/.
Index ¶
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type GrammarType ¶
type GrammarType uint32
GrammarType determines the type of grammar
const ( ErrorGrammar GrammarType = iota // extra grammar when errors occur WhitespaceGrammar LiteralGrammar NumberGrammar StringGrammar StartObjectGrammar // { EndObjectGrammar // } StartArrayGrammar // [ EndArrayGrammar // ] )
GrammarType values.
func (GrammarType) String ¶
func (gt GrammarType) String() string
String returns the string representation of a GrammarType.
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser is the state for the lexer.
func NewParser ¶
func NewParser(r *parse.Input) *Parser
NewParser returns a new Parser for a given io.Reader.
Example ¶
p := NewParser(parse.NewInputString(`{"key": 5}`)) out := "" for { state := p.State() gt, data := p.Next() if gt == ErrorGrammar { break } out += string(data) if state == ObjectKeyState && gt != EndObjectGrammar { out += ":" } // not handling comma insertion } fmt.Println(out)
Output: {"key":5}
func (*Parser) Err ¶
Err returns the error encountered during tokenization, this is often io.EOF but also other errors can be returned.
func (*Parser) Next ¶
func (p *Parser) Next() (GrammarType, []byte)
Next returns the next Grammar. It returns ErrorGrammar when an error was encountered. Using Err() one can retrieve the error message.
Click to show internal directories.
Click to hide internal directories.