iojson

package
v0.31.1 Latest Latest
Warning

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

Go to latest
Published: Feb 15, 2026 License: MIT Imports: 6 Imported by: 0

Documentation

Overview

iojson are utilities for reading and writing JSON IO from a command line interface perspective

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func MarshalError

func MarshalError(msg string, data map[string]any) string

MarshalError is a utility for creating an error struct, it will first attempt the marshal the struct, if that fails it will return return a manually constructed JSON blob with the provided error msg and a note that there was a marashling error and the this indicates a bug in the software.

func Write

func Write(obj any, opts ...Option) error

Write calls WriteWith with os.Stdout and os.Stderr.

func WriteError

func WriteError(str string, data map[string]any) error

func WriteLine

func WriteLine(w io.Writer, obj any) error

WriteLine writes obj as compact JSON (no indent) to w. Intended for JSON lines output where multiple objects are written sequentially.

func WriteWith

func WriteWith(w io.Writer, ew io.Writer, obj any, opts ...Option) error

WriteWith writes obj as JSON to w, with errors written to ew.

Types

type Error

type Error struct {
	Message string         `json:"message"`
	Data    map[string]any `json:"data"`
}

Error is the standard error format type that is returned when errors happen.

type FileReader

type FileReader[T any] struct {
	// contains filtered or unexported fields
}

func (*FileReader[T]) Flag

func (fr *FileReader[T]) Flag() *cli.StringFlag

func (*FileReader[T]) Read

func (fr *FileReader[T]) Read() (T, error)

type Option

type Option func(*Options)

Option is a functional option for configuring JSON output.

func WithIndent

func WithIndent(indent bool) Option

WithIndent sets whether to indent JSON output (default: true).

type Options

type Options struct {
	Indent bool
}

Options configures JSON output behavior.

Jump to

Keyboard shortcuts

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