package json

import "github.com/tdewolff/minify/v2/json"

Package json minifies JSON following the specifications at http://json.org/.

Index

Examples

Functions

func Minify

func Minify(m *minify.M, w io.Writer, r io.Reader, params map[string]string) error

Minify minifies JSON data, it reads from r and writes to w.

Example

Code:

{
	m := minify.New()
	m.AddFuncRegexp(regexp.MustCompile("[/+]json$"), Minify)

	if err := m.Minify("application/json", os.Stdout, os.Stdin); err != nil {
		panic(err)
	}
}

Types

type Minifier

type Minifier struct {
	Precision   int  // number of significant digits
	KeepNumbers bool // prevent numbers from being minified
}

Minifier is a JSON minifier.

func (*Minifier) Minify

func (o *Minifier) Minify(_ *minify.M, w io.Writer, r io.Reader, _ map[string]string) error

Minify minifies JSON data, it reads from r and writes to w.

Source Files

json.go

Version
v2.21.3 (latest)
Published
Jan 14, 2025
Platform
linux/amd64
Imports
4 packages
Last checked
4 days ago

Tools for package owners.