Documentation
¶
Overview ¶
Package json implements JSON for JavaScript values, whose strings are in WTF-8: parsing text into values, calling a reviver on them, converting values to text, and the lexical grammar.
A scanning function takes the text and the index at which to start. It returns the index after what it scanned and true, or the index of the first byte that does not fit the grammar and false. An index equal to the length of the text means that the text ended too early.
Index ¶
- func AppendQuote(dst []byte, s wtf8.String) []byte
- func IsRawJSON(v storage.Value) bool
- func IsSpace(c byte) bool
- func RawJSON(cx *engine.ExecutionContext, text storage.Value) storage.Value
- func Revive(cx *engine.ExecutionContext, v storage.Value, rec *Record, fn *storage.Object) storage.Value
- func ScanLiteral(s wtf8.String, i int, word wtf8.String) (int, bool)
- func ScanNumber(s wtf8.String, i int, poll func()) (float64, int, bool)
- func ScanString(s wtf8.String, i int, b *wtf8.Buffer) (wtf8.String, int, bool)
- func SkipSpace(s wtf8.String, i int) int
- func Valid(s wtf8.String, poll func()) (int, bool)
- type Parser
- type Record
- type Stringifier
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func AppendQuote ¶
AppendQuote implements QuoteJSONString for the string s and appends the result to dst.
func Revive ¶
func Revive(cx *engine.ExecutionContext, v storage.Value, rec *Record, fn *storage.Object) storage.Value
Revive implements the steps of JSON.parse that call the function fn on the value v and its parts. v and rec are the results of ParseWithRecord.
func ScanLiteral ¶
ScanLiteral scans the literal word, such as true, at i.
func ScanNumber ¶
ScanNumber scans a number at i and returns its value. poll, which may be nil, is called now and then while a long number is scanned, and may stop the scan by panicking.
func ScanString ¶
ScanString scans a string whose opening quote is at i and returns its contents. The contents of a string without escapes are a substring of s. Otherwise they are built in b, which ScanString resets first.
Types ¶
type Parser ¶
type Parser struct {
// contains filtered or unexported fields
}
Parser parses JSON text into JavaScript values. The zero value is ready to use. A Parser keeps scratch storage between calls but no references to values.
func (*Parser) Parse ¶
Parse parses the JSON text src into a value of cx. It throws a SyntaxError when src is not a JSON text.
func (*Parser) ParseWithRecord ¶
func (p *Parser) ParseWithRecord(cx *engine.ExecutionContext, src wtf8.String) (storage.Value, *Record)
ParseWithRecord is like Parser.Parse, and also returns the parse record of the value.
type Record ¶
type Record struct {
// contains filtered or unexported fields
}
Record is a JSON Parse Record: what a part of the text produced, for Revive.
type Stringifier ¶
type Stringifier struct {
// contains filtered or unexported fields
}
Stringifier converts values to JSON text. The zero value is ready to use. A Stringifier keeps its output buffer between calls.
func (*Stringifier) Stringify ¶
func (s *Stringifier) Stringify(cx *engine.ExecutionContext, value, replacer, space storage.Value) storage.Value
Stringify implements JSON.stringify.