Documentation
¶
Overview ¶
Package jrp rewrites JSON documents with a layout that follows the shape of the data instead of putting every value on its own line.
A container collapses onto a single line unless it holds an object somewhere inside it, so a flat record stays readable as one line while anything with real structure below it opens up. Options.MaxItems and Options.MaxWidth add optional hard caps that fall back to conventional one-member-per-line output.
The rewrite is textual rather than a round trip through a Go value: key order and number formatting are preserved exactly as written, which re-marshalling a decoded value would not do.
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type Options ¶
type Options struct {
// Indent is one level of indentation in an expanded container.
Indent string
// MaxWidth, when greater than zero, expands any container whose one-line
// form would reach past this column. Zero means no width limit.
//
// The limit is best effort: a single string literal longer than MaxWidth
// still overflows its line, because JSON strings cannot be wrapped.
MaxWidth int
// MaxItems, when greater than zero, expands any container that holds more
// than this many members or elements. Zero means no limit.
MaxItems int
// SpaceInBraces pads inline objects, as { "a": 1 } rather than {"a": 1}.
SpaceInBraces bool
// SpaceInBrackets pads inline arrays, as [ 1, 2 ] rather than [1, 2].
SpaceInBrackets bool
// SortKeys emits object members in lexicographic order instead of the
// order they appear in the input.
SortKeys bool
// TrailingNewline appends a final newline to the output.
TrailingNewline bool
}
Options controls how Format lays out a document.
The layout rule that gives the tool its name is not optional: a container collapses onto one line unless it holds an object somewhere inside it, so a plain record like { "id": 7, "name": "example" } stays a single line however long it gets, while anything with real structure below it opens up. MaxItems and MaxWidth sit on top of that as hard caps for people who do want a ceiling; both are off by default.