class

JSON::Tight::Formatter

Inherits Reference < Object

Applies the layout strategies described on JSON::Tight. Build one directly instead of calling JSON::Tight.generate to reuse it across documents or to control the indent used by expanded layouts.

formatter = JSON::Tight::Formatter.new(width: 100, indent: 4)
formatter.format(STDOUT, value)

Constructors

new(width : Int32 = DEFAULT_WIDTH, indent : Int32 = DEFAULT_INDENT)
Source

Instance methods

format(io : IO, value : JSON::Any) : Nil

Writes value to io, formatted and ending in a newline.

Source
format(io : IO, value) : Nil

Writes value, which may be anything that responds to #to_json, to io, formatted and ending in a newline.

Source
format(io : IO, *, json : String) : Nil

Parses json and writes it to io, reformatted and ending in a newline. Raises JSON::ParseException if json is not valid JSON.

Source
indent

Spaces per nesting level in expanded layouts.

Source
width

Width budget for a line's content, excluding leading indentation.

Source