jsoncfmt

package
v3.0.0-rc.1 Latest Latest
Warning

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

Go to latest
Published: Jul 16, 2026 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Overview

Package jsoncfmt provides a Formatter for JSONC (JSON with Comments) files.

The formatter uses tailscale/hujson's CST (concrete syntax tree) for lossless parsing and serialization. Comments (line and block) and trailing commas are preserved through the format cycle.

Formatting walks the CST to apply indentation and normalize spacing. This is idempotent by construction — the same tree always produces the same output regardless of original formatting.

Standard JSON input produces standard JSON output (no trailing commas added). JSONC input preserves trailing commas on multiline structures.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func DefaultOptions

func DefaultOptions() formatter.Options

DefaultOptions returns the default formatting options for JSONC.

Types

type Formatter

type Formatter struct{}

Formatter formats JSONC files using CST-based indentation. It is stateless and safe for concurrent use.

func (Formatter) Format

func (Formatter) Format(src []byte, opts formatter.Options) ([]byte, error)

Format returns the canonically formatted version of src. Returns an error if src is not valid JSONC (JSON with comments and trailing commas).

Jump to

Keyboard shortcuts

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