Help us shape the future of Go! Take the 2026 Go Developer Survey

jsont

package module
v0.0.0-...-d6eb0e0 Latest Latest
Warning

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

Go to latest
Published: Jan 21, 2016 License: Apache-2.0 Imports: 5 Imported by: 1

README

jsont

A JSON tokenizer that also emits insignificant tokens like whitespaces.

{ "Hello" : "World" }

Will be split into the following tokens:

|{| |"Hello"| |:| |"World"| |}|

Usage

tokenizer := jsont.NewTokenizer(strings.NewReader(jsonInput))

for tokenizer.Next() {
	token := tokenizer.Token()
	fmt.Println(token.Type)
	fmt.Println(token.Value)
}                                                                                                                                   

if tokenizer.Error() != nil {
	fmt.Println(tokenizer.Error())
}

Disclaimer

Documentation

Overview

Package jsont provides a non validating json tokenizer that also emits insignificant tokens (like whitespace).

Example

The following json:

{ "Hello" : "World" }

Will be split into the following tokens:

|{| |"Hello"| |:| |"World"| |}|

Usage

Usage example:

tokenizer := jsont.NewTokenizer(strings.NewReader(jsonInput))

for tokenizer.Next() {
	token := tokenizer.Token()
	fmt.Println(token.Type)
	fmt.Println(token.Value)
}

if tokenizer.Error() != nil {
	fmt.Println(tokenizer.Error())
}

Disclaimer

The behavior of this tokenizer is rarely useful. In fact only consider using it, if you are interested in whitespace tokens and don't need to check if the given input is valid json.

Index

Constants

View Source
const (
	Empty = iota
	Whitespace
	ObjectStart
	ObjectEnd
	ArrayStart
	ArrayEnd
	Colon
	Comma
	FieldName
	True
	False
	Null
	Integer
	Float
	String
	Unknown
)

Variables

This section is empty.

Functions

This section is empty.

Types

type Token

type Token struct {
	Type  TokenType
	Value string
}

type TokenType

type TokenType int

type Tokenizer

type Tokenizer interface {

	// Scan advances the Scanner to the next token, which will then be available
	// through the Token method. It returns false if no more Tokens are available,
	// either because of reaching the end of the input or an error.
	Next() bool

	// Token returns the most recent token generated by a call to Next.
	Token() Token

	// Error returns the first non-EOF error that was encountered by the Tokenizer.
	Error() error
}

func NewTokenizer

func NewTokenizer(reader io.Reader) Tokenizer

Jump to

Keyboard shortcuts

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