jst

package
v0.0.4 Latest Latest
Warning

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

Go to latest
Published: Aug 28, 2021 License: MIT Imports: 7 Imported by: 0

Documentation

Overview

"jst" -- JSON Table -- is a format that's parsable as JSON, while sprucing up the display to humans using the non-significant whitespace cleverly. Regular data can be piped into a JSON Table formatter, and some simple heuristics will attempt to detect table structure.

Lists can be turned into column-aligned tables:

  • Every time there's a list, and the first entry is a map, we'll try to treat it as a table.
  • Every time a map in that list starts with the same first key as the first map did, it's a table row.
  • Every thing that's a table row will be buffered, and we try to fit each key into a table column.
  • (FUTURE) You can manually specify keys that should be excluded from columns; these will be shifted to the end and packed tightly.
  • We'll store the size of the widest value for each column. We'll need to do this over every row so we can align output spacing.
  • If there's a map in the list that doesn't start with the same first key, it's a table exclusion, and gets formatted densely.
  • If a map has a value that's a list, we attempt to apply this whole ruleset over again from the top.
  • If a table is detected, we'll print the key on its own new line, slightly indented, together with the list open. Then, emit the table onsubsequent further indented lines.

Maps can also be turned into column-aligned tables:

  • You have to use additional configuration to engage this: by default, only lists trigger table mode.
  • The search for table rows begins anew with each map value. The map keys form a defacto first column.
  • Thereafter, all the rules for handling each table row is the same the rules described above for lists.

Decorations can be applied:

  • Defaults include colorizing map keys vs values, and optionally colorizing column names distinctly from other keys.
  • These colorations operate by ANSI codes (e.g., they work in terminals). The palette is accordingly limited.
  • (FUTURE) You can override colors of specific keys and values.

The overall nature of detecting traits of the data (particularly, size) means JSON Tables cannot be created streamingly; we have to process the entire structure first, and only then can we begin to output correctly aligned data. (It's for this reason that this is implemented over LD Nodes, and would be somewhat painful to implement using just refmt Tokens -- we'd end up buffering *all* the tokens anyway, and wanting to build an index, etc.)

There's no unmarshal functions because unmarshal is just... regular JSON unmarshal.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Marshal

func Marshal(n ld.Node, w io.Writer) error

func MarshalConfigured

func MarshalConfigured(cfg Config, n ld.Node, w io.Writer) error

Types

type Color

type Color struct {
	Enabled      bool
	KeyHighlight []byte
	PlainValue   []byte
}

type Config

type Config struct {
	Indent []byte
	Color  Color
}

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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