jsonout

package
v1.12.0 Latest Latest
Warning

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

Go to latest
Published: Aug 20, 2026 License: MIT Imports: 4 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 jsonout writes JSON documents the way Ruby's JSON.generate writes them: members in the order the caller states, no whitespace, and Ruby's escape set for strings.

It exists because every structured CLI surface is compared byte for byte against the Ruby oracle, and encoding/json cannot produce those bytes: Go sorts map keys, escapes `<`, `>`, `&`, U+2028 and U+2029, and spells floats with its own shortest-round-trip algorithm. The record package already owns the Ruby-compatible primitives (string escaping, number spelling, whole-value emission); this package is the ordered-object writer built on top of them.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

type Writer struct {
	// contains filtered or unexported fields
}

Writer accumulates one JSON document. Members appear in call order.

func New

func New() *Writer

New returns an empty writer.

func (*Writer) BeginArray

func (w *Writer) BeginArray()

BeginArray opens `[`.

func (*Writer) BeginObject

func (w *Writer) BeginObject()

BeginObject opens `{`.

func (*Writer) Bool

func (w *Writer) Bool(value bool)

Bool writes `true` or `false`.

func (*Writer) Bytes

func (w *Writer) Bytes() []byte

Bytes is the document written so far.

func (*Writer) EndArray

func (w *Writer) EndArray()

EndArray closes `]`.

func (*Writer) EndObject

func (w *Writer) EndObject()

EndObject closes `}`.

func (*Writer) Err

func (w *Writer) Err() error

Err reports the first error a value refused to encode with.

func (*Writer) Int

func (w *Writer) Int(value int)

Int writes an integer.

func (*Writer) Key

func (w *Writer) Key(name string)

Key writes an object member name; the next value written becomes its value.

func (*Writer) KeyBool

func (w *Writer) KeyBool(name string, value bool)

func (*Writer) KeyInt

func (w *Writer) KeyInt(name string, value int)

func (*Writer) KeyNull

func (w *Writer) KeyNull(name string)

func (*Writer) KeyStr

func (w *Writer) KeyStr(name, value string)

KeyStr, KeyStrOrNull, KeyBool and KeyInt are the one-call spellings of the overwhelmingly common key/value pair.

func (*Writer) KeyStrOrNull

func (w *Writer) KeyStrOrNull(name, value string)

func (*Writer) Null

func (w *Writer) Null()

Null writes `null`.

func (*Writer) Raw

func (w *Writer) Raw(raw json.RawMessage)

Raw writes an already-parsed JSON value with Ruby's spelling. A nil or empty value is `null`, which is how an absent record field reads.

func (*Writer) Str

func (w *Writer) Str(value string)

Str writes a JSON string.

func (*Writer) StrOrNull

func (w *Writer) StrOrNull(value string)

StrOrNull writes a string, or `null` when it is empty.

func (*Writer) String

func (w *Writer) String() string

String is the document written so far.

func (*Writer) Strings

func (w *Writer) Strings(values []string)

Strings writes an array of strings.

Jump to

Keyboard shortcuts

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