Defines JSON generator.
import java.io.StringWriter
import scala.language.implicitConversions
import grapple.json.{ *, given }
val buf = StringWriter()
val out = JsonGenerator(buf)
try
out.writeStartObject() // start root object
out.write("id", 1000)
out.write("name", "lupita")
out.writeStartArray("groups") // start nested array
out.write("lupita")
out.write("admin")
out.write("sudoer")
out.writeEnd() // end nested array
out.writeStartObject("info") // start nested object
out.write("home", "/home/lupita")
out.write("storage", "8 GiB")
out.writeEnd() // end nested object
out.writeEnd() // end root object
out.flush()
val json = Json.parse(buf.toString)
assert { json("id") == JsonNumber(1000) }
assert { json("name") == JsonString("lupita") }
assert { json("groups") == Json.arr("lupita", "admin", "sudoer") }
assert { json("info") == Json.obj("home" -> "/home/lupita", "storage" -> "8 GiB") }
finally
out.close()
Attributes
- See also
- Companion
- object
- Graph
-
- Supertypes
-
trait AutoCloseableclass Objecttrait Matchableclass Any
Members list
Value members
Abstract methods
Closes writer.
Closes writer.
Attributes
Flushes writer.
Flushes writer.
Attributes
Writes field to object context.
Writes field to object context.
Attributes
Writes value to array context.
Writes value to array context.
Attributes
Writes closing brace or bracket based on current context.
Writes closing brace or bracket based on current context.
Attributes
Writes opening bracket to start array context.
Writes opening bracket to start array context.
Attributes
Writes field declaration and opening bracket to start array context.
Writes field declaration and opening bracket to start array context.
Value parameters
- key
-
object key
Attributes
Writes opening brace to start object context.
Writes opening brace to start object context.
Attributes
Writes field declaration and opening brace to start object context.
Writes field declaration and opening brace to start object context.
Value parameters
- key
-
object key
Attributes
Concrete methods
Writes field to object context.
Writes field to object context.
Attributes
Writes field to object context.
Writes field to object context.
Attributes
Writes field to object context.
Writes field to object context.
Attributes
Writes field to object context.
Writes field to object context.
Attributes
Writes field to object context.
Writes field to object context.
Attributes
Writes field to object context.
Writes field to object context.
Attributes
Writes field to object context.
Writes field to object context.
Attributes
Writes field to object context.
Writes field to object context.
Attributes
Writes value to array context.
Writes value to array context.
Attributes
Writes value to array context.
Writes value to array context.
Attributes
Writes value to array context.
Writes value to array context.
Attributes
Writes value to array context.
Writes value to array context.
Attributes
Writes value to array context.
Writes value to array context.
Attributes
Writes value to array context.
Writes value to array context.
Attributes
Writes value to array context.
Writes value to array context.
Attributes
Writes value to array context.
Writes value to array context.
Attributes
Writes field with null value to object context.
Writes field with null value to object context.
Attributes
Writes null value to array context.
Writes null value to array context.