Import std.data.json
JsonWriter
class
Public Class JsonWriter Implements Printable
Writes a JSON document a token at a time: BeginObject, then each Key and its value, then EndObject; BeginArray, its values, then EndArray; or one value alone. With an indent of 0, the text is on one line with no spaces, and otherwise each value of an array or an object is on a line of its own, indented that many spaces more than what holds it, and a key's value is after ": ". Each method panics when its token can't come next, as a Key outside an object, or a second value after the document's, at its caller.
Examples
Local writer = JsonWriter()
writer.BeginObject()
writer.Key("name")
writer.WriteString("Ada")
writer.Key("scores")
writer.BeginArray()
writer.WriteInt(3)
writer.WriteInt(5)
writer.EndArray()
writer.EndObject()
Expect(writer.IsComplete)
Local written = Try Json.Read(writer.ToString())
Expect(written.Path("scores[1]")?.AsInt() == 5)-
A JsonWriter that indents by
indentspaces a level, or writes on one line for 0. Panics whenindentis below 0. -
Whether the document's value is all written.
-
Starts an object, whose keys and values come next. Panics where a value can't go.
-
Ends the object that's open. Panics when the innermost open one is an array, or a key has no value.
-
Starts an array, whose values come next. Panics where a value can't go.
-
Ends the array that's open. Panics when the innermost open one is an object.
-
An object's next key, whose value comes next.
-
Writes
valueas a string, in quotes, with JSON's escapes. Panics where a value can't go. -
Writes
valueas a number. Panics where a value can't go. -
Writes
valueas a number. Panics where a value can't go. -
A Double, as the shortest text that reads back as it, with ".0" after one that would read as an integer, so it reads back as a DOUBLE. Panics for NaN or an infinity, which JSON doesn't have.
-
Writes
valueas true or false. Panics where a value can't go. -
Writes null. Panics where a value can't go.
-
The JSON written so far.
Report an issue with this page or with FutureBlitz on GitHub.