jsonenc

package
v1.7.0 Latest Latest
Warning

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

Go to latest
Published: Nov 11, 2026 License: MIT Imports: 13 Imported by: 0

Documentation

Overview

Package jsonenc encodes values as encoding/json does, byte for byte, except that a nil slice is written as [] instead of null: Tern sends [] for pages, typed endpoints and live components, so their TypeScript types are T[] rather than T[] | null.

It's faster than encoding/json followed by a copy that fills in nil slices: each type's encoder is built once, and nothing is copied. Values that encode themselves (json.Marshaler, encoding.TextMarshaler) and the rare struct tag options it doesn't implement go through encoding/json.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Append

func Append(b []byte, v any) ([]byte, error)

Append appends the JSON encoding of v to b.

func Marshal

func Marshal(v any) ([]byte, error)

Marshal returns the JSON encoding of v.

Types

type Verbatim

type Verbatim []byte

Verbatim is JSON this package wrote, written again as it is: no checking, compacting or escaping. Only for its own output, which is already compact and safe to inline in HTML.

func (Verbatim) MarshalJSON

func (v Verbatim) MarshalJSON() ([]byte, error)

MarshalJSON is for encoding/json, which checks and compacts it.

func (*Verbatim) UnmarshalJSON

func (v *Verbatim) UnmarshalJSON(b []byte) error

UnmarshalJSON keeps the raw JSON, as json.RawMessage does.

Jump to

Keyboard shortcuts

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