class JSON::Tight::Formatter

Overview

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)

Defined in:

json-tight.cr

Constructors

Instance Method Summary

Constructor Detail

def self.new(width : Int32 = DEFAULT_WIDTH, indent : Int32 = DEFAULT_INDENT) #

[View source]

Instance Method Detail

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

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


[View source]
def format(io : IO, value) : Nil #

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


[View source]
def 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.


[View source]
def indent : Int32 #

Spaces per nesting level in expanded layouts.


[View source]
def width : Int32 #

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


[View source]