Help us shape the future of Go! Take the 2026 Go Developer Survey

jsoncompact

package
v1.3.0 Latest Latest
Warning

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

Go to latest
Published: Mar 6, 2026 License: AGPL-3.0, AGPL-3.0-or-later Imports: 2 Imported by: 0

Documentation

Overview

Package jsoncompact provides JSON compression by trimming arrays to a configurable maximum.

Index

Constants

View Source
const (
	DefaultMaxArrayItems = 3
	DefaultMaxStringLen  = 500
	DefaultMaxDepth      = 0 // unlimited
)

Default values for compaction options.

Variables

This section is empty.

Functions

func Compact

func Compact(data []byte, opts *Options) ([]byte, error)

Compact compresses JSON bytes by trimming arrays and strings. Returns error if input is not valid JSON. If opts is nil, DefaultOptions() is used.

func CompactValue

func CompactValue(v any, opts *Options) any

CompactValue compresses a parsed JSON value (any type from json.Unmarshal). If opts is nil, DefaultOptions() is used.

Types

type Options

type Options struct {
	MaxArrayItems int // Trim arrays to N items (0 = no limit)
	MaxStringLen  int // Truncate strings longer than N chars (0 = no limit)
	MaxDepth      int // Max recursion depth (0 = unlimited)
}

Options controls JSON compaction behavior.

func DefaultOptions

func DefaultOptions() *Options

DefaultOptions returns the default compaction settings.

Jump to

Keyboard shortcuts

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