json

package
v0.2.0 Latest Latest
Warning

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

Go to latest
Published: Nov 27, 2026 License: 0BSD Imports: 9 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

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

Constants

This section is empty.

Variables

This section is empty.

Functions

func AppendQuote

func AppendQuote(dst []byte, s wtf8.String) []byte

AppendQuote implements QuoteJSONString for the string s and appends the result to dst.

func IsRawJSON

func IsRawJSON(v storage.Value) bool

IsRawJSON implements JSON.isRawJSON.

func IsSpace

func IsSpace(c byte) bool

IsSpace reports whether c is JSON whitespace.

func RawJSON

func RawJSON(cx *engine.ExecutionContext, text storage.Value) storage.Value

RawJSON implements JSON.rawJSON.

func Revive

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

func ScanLiteral(s wtf8.String, i int, word wtf8.String) (int, bool)

ScanLiteral scans the literal word, such as true, at i.

func ScanNumber

func ScanNumber(s wtf8.String, i int, poll func()) (float64, int, bool)

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

func ScanString(s wtf8.String, i int, b *wtf8.Buffer) (wtf8.String, int, bool)

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.

func SkipSpace

func SkipSpace(s wtf8.String, i int) int

SkipSpace returns the index of the first byte at or after i that is not whitespace.

func Valid

func Valid(s wtf8.String, poll func()) (int, bool)

Valid reports whether s is a JSON text. When it is not, it also returns the index at which the grammar fails. poll is as for ScanNumber.

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

func (p *Parser) Parse(cx *engine.ExecutionContext, src wtf8.String) storage.Value

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.

Jump to

Keyboard shortcuts

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