jsonfmt

package
v1.5.0 Latest Latest
Warning

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

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

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Beautify

func Beautify(data []byte, indent string) ([]byte, error)

Beautify formats JSON with indentation

func Format

func Format(data []byte, opts Options) ([]byte, error)

Format formats JSON with custom options

func GetType

func GetType(data []byte) string

GetType returns the JSON type of the root element

func IsValid

func IsValid(data []byte) bool

IsValid returns true if data is valid JSON

func Keys

func Keys(data []byte) ([]string, error)

Keys returns all keys from a JSON object (recursively)

func Minify

func Minify(data []byte) ([]byte, error)

Minify compacts JSON by removing whitespace

func MustBeautify

func MustBeautify(data []byte) []byte

MustBeautify formats JSON and panics on error

func MustMinify

func MustMinify(data []byte) []byte

MustMinify compacts JSON and panics on error

func RunJSONFmt

func RunJSONFmt(w io.Writer, args []string, opts Options) error

RunJSONFmt formats JSON input

func SortKeys

func SortKeys(data []byte) ([]byte, error)

SortKeys returns JSON with sorted object keys

func Validate

func Validate(data []byte) error

Validate checks if data is valid JSON

Types

type Options

type Options struct {
	Minify     bool   // -m: minify (compact) output
	Indent     string // -i: indentation string (default "  ")
	SortKeys   bool   // -s: sort object keys
	Validate   bool   // -v: validate only, don't output
	EscapeHTML bool   // -e: escape HTML characters
	JSON       bool   // --json: output result as JSON (for validate mode)
	Tab        bool   // -t: use tabs for indentation
}

Options configures the json format command behavior

type Result

type Result struct {
	Valid bool   `json:"valid"`
	Error string `json:"error,omitempty"`
	File  string `json:"file,omitempty"`
}

Result represents the JSON output for validate mode

type Stats

type Stats struct {
	Type        string `json:"type"`
	Keys        int    `json:"keys,omitempty"`
	Elements    int    `json:"elements,omitempty"`
	Depth       int    `json:"depth"`
	Size        int    `json:"size"`
	MinifiedLen int    `json:"minifiedLen"`
}

Stats returns statistics about JSON data

func GetStats

func GetStats(data []byte) (*Stats, error)

GetStats returns statistics about JSON data

Jump to

Keyboard shortcuts

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