A JSON builder generates valid JSON.
A JSON::Error
is raised if attempting to generate an invalid JSON (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).
Creates a JSON::Builder
that will write to the given IO
.
Writes the start of an array, invokes the block, and the writes the end of it.
Writes a boolean value.
Writes the end of an array.
Signals the end of a JSON document.
Writes the end of an object.
Writes an object's field and then invokes the block.
Writes an object's field and value.
Flushes the underlying IO
.
Sets the indent level (number of spaces).
Sets the indent string.
By default the maximum nesting of arrays/objects is 99.
By default the maximum nesting of arrays/objects is 99.
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 #null
value.
Writes a float.
Writes an integer.
Writes the start of an object, invokes the block, and the writes the end of it.
Writes a raw value, considered a scalar, directly into the IO without processing.
Writes a scalar value.
Writes a scalar value.
Writes a scalar value.
Writes a scalar value.
Writes the start of an array.
Starts a document.
Writes the start of an object.
Writes a string.
Reference
Reference
Object
Object
Creates a JSON::Builder
that will write to the given IO
.
Writes the start of an array, invokes the block, and the writes the end of it.
Writes the end of an array.
Writes the end of an object.
Writes an object's field and then invokes the block. This is equivalent of invoking #string(value)
and then invoking the block.
Writes an object's field and value. The field's name is first converted to a String
by invoking to_s
on it.
By default the maximum nesting of arrays/objects is 99. Nesting more than this will result in a JSON::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 JSON::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 the start of an object, invokes the block, and the writes the end of it.
Writes a raw value, considered a scalar, directly into the IO without processing. This is the only method that might lead to invalid JSON being generated, so you must be sure that string contains a valid JSON string.
Writes the start of an array.
Starts a document.
Writes the start of an object.
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.
© 2012–2020 Manas Technology Solutions.
Licensed under the Apache License, Version 2.0.
https://crystal-lang.org/api/0.35.1/JSON/Builder.html