jsonutil

package
v1.4.6 Latest Latest
Warning

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

Go to latest
Published: Jul 8, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package jsonutil provides JSON formatting utilities.

The package supports pretty printing with indentation. Keys are always sorted alphabetically by Go's json.Marshal, ensuring consistent output for diffing.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func TryFormat

func TryFormat(value string) (string, bool)

TryFormat attempts to format a JSON string with indentation. Returns the formatted string and true if successful, or the original string and false if not valid JSON. This is useful for commands that need to know whether formatting was applied.

HTML escaping is disabled so that characters like &, <, > survive verbatim instead of being mangled into &, <, > — secret/parameter values are not HTML and are never rendered in a browser context.

Numbers are decoded with UseNumber so their exact literal is preserved: decoding into float64 (the default) silently loses integer precision beyond 2^53 and collapses 1.0/1, which would make genuinely different values format identically (and diff as "identical").

func TryFormatOrWarn

func TryFormatOrWarn(value string, errW io.Writer, name string) string

TryFormatOrWarn formats JSON or warns and returns original. If name is non-empty, includes it in the warning message.

func TryFormatOrWarn2

func TryFormatOrWarn2(v1, v2 string, errW io.Writer, name string) (string, string)

TryFormatOrWarn2 formats both JSONs or warns and returns originals. If name is non-empty, includes it in the warning message.

Types

This section is empty.

Jump to

Keyboard shortcuts

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