class NASON::Builder
Overview
A NASON builder generates valid NASON.
A NASON::Error
is raised if attempting to generate an invalid NASON
(for example, if invoking #end_array
without a matching #start_array
,
or trying to use a non-string value as an object's field name).
Defined in:
big/nason.crnason/builder.cr
Constructors
-
.new(io : IO)
Creates a
NASON::Builder
that will write to the givenIO
.
Instance Method Summary
-
#array(&)
Writes the start of an array, invokes the block, and the writes the end of it.
-
#bool(value : Bool) : Nil
Writes a boolean value.
- #document(&)
-
#end_array : Nil
Writes the end of an array.
-
#end_document : Nil
Signals the end of a NASON document.
-
#end_object : Nil
Writes the end of an object.
-
#field(name, value)
Writes an object's field and value.
-
#field(name, &)
Writes an object's field and then invokes the block.
-
#flush
Flushes the underlying
IO
. -
#indent=(string : String)
Sets the indent string.
-
#indent=(level : Int)
Sets the indent level (number of spaces).
-
#max_nesting : Int32
By default the maximum nesting of arrays/objects is 99.
-
#max_nesting=(max_nesting : Int32)
By default the maximum nesting of arrays/objects is 99.
-
#next_is_object_key? : Bool
Returns
true
if the next thing that must pushed into this builder is an object key (so a string) or the end of an object. -
#null : Nil
Writes a
#null
value. -
#number(number : Int) : Nil
Writes an integer.
-
#number(number : Float) : Nil
Writes a float.
-
#number(number : BigDecimal) : Nil
Writes a big decimal.
-
#object(&)
Writes the start of an object, invokes the block, and the writes the end of it.
-
#raw(string : String) : Nil
Writes a raw value, considered a scalar, directly into the IO without processing.
-
#scalar(value : Nil)
Writes a scalar value.
-
#scalar(value : Null)
Writes a scalar value.
-
#scalar(value : Bool)
Writes a scalar value.
-
#scalar(value : Int | Float) : Nil
Writes a scalar value.
-
#scalar(value : String) : Nil
Writes a scalar value.
-
#start_array : Nil
Writes the start of an array.
-
#start_document : Nil
Starts a document.
-
#start_object : Nil
Writes the start of an object.
-
#string(value) : Nil
Writes a string.
Instance methods inherited from class Reference
==(other : NASON::Any)
==
Instance methods inherited from class Object
===(other : NASON::Any)
===,
nil_or_null?
nil_or_null?,
not_null!
not_null!,
null?
null?,
to_nason(io : IO) : Nilto_nason : String to_nason, to_pretty_json(indent : String = " ") : String
to_pretty_json(io : IO, indent : String = " ") : Nil to_pretty_json
Class methods inherited from class Object
from_nason(string_or_io, root : String)from_nason(string_or_io) from_nason
Constructor Detail
Instance Method Detail
Writes an object's field and value.
The field's name is first converted to a String
by invoking
to_s
on it.
Writes an object's field and then invokes the block.
This is equivalent of invoking #string(value)
and then
invoking the block.
By default the maximum nesting of arrays/objects is 99. Nesting more than this will result in a NASON::Error. Changing the value of this property allows more/less nesting.
By default the maximum nesting of arrays/objects is 99. Nesting more than this will result in a NASON::Error. Changing the value of this property allows more/less nesting.
Returns true
if the next thing that must pushed into this
builder is an object key (so a string) or the end of an object.
Writes a raw value, considered a scalar, directly into the IO without processing. This is the only method that might lead to invalid NASON being generated, so you must be sure that string contains a valid NASON string.
Writes a string. The given value is first converted to a String
by invoking to_s
on it.
This method can also be used to write the name of an object field.