Json

grapple.json.Json
object Json

Provides JSON utilities.

import scala.language.implicitConversions

import grapple.json.{ *, given }

// Create JSON object
val user = Json.obj("id" -> 1000, "name" -> "lupita")

// Create JSON array
val info = Json.arr(user, "/home/lupita", 8L * 1024 * 1024 * 1024)

// Parse JSON text
val root = Json.parse("""{ "id": 0, "name": "root" }""")

case class User(id: Int, name: String)

given userOutput: JsonOutput[User] with
 def write(u: User) = Json.obj("id" -> u.id, "name" -> u.name)

// Convert value to JSON object
val nobody = Json.toJson(User(65534, "nobody"))

Attributes

Graph
Supertypes
class Object
trait Matchable
class Any
Self type
Json.type

Members list

Value members

Concrete methods

def arr(values: JsonValue*): JsonArray

Creates JSON array with supplied values.

Creates JSON array with supplied values.

Attributes

def obj(fields: (String, JsonValue)*): JsonObject

Creates JSON object with supplied fields.

Creates JSON object with supplied fields.

Attributes

def parse(input: String): JsonStructure

Parses JSON structure from input.

Parses JSON structure from input.

Attributes

Throws
JsonParserError

if input cannot be parsed to JSON structure

def parse(input: Array[Byte]): JsonStructure

Parses JSON structure from input.

Parses JSON structure from input.

Attributes

Throws
JsonParserError

if input cannot be parsed to JSON structure

def parse(input: Array[Byte], offset: Int, length: Int): JsonStructure

Parses JSON structure from input.

Parses JSON structure from input.

Attributes

Throws
JsonParserError

if input cannot be parsed to JSON structure

def parse(input: Reader): JsonStructure

Parses JSON structure from input.

Parses JSON structure from input.

Attributes

Throws
JsonParserError

if input cannot be parsed to JSON structure

Note

Closes input on return.

def parse(input: InputStream): JsonStructure

Parses JSON structure from input.

Parses JSON structure from input.

Attributes

Throws
JsonParserError

if input cannot be parsed to JSON structure

Note

Closes input on return.

def parse(input: File): JsonStructure

Parses JSON structure from input.

Parses JSON structure from input.

Attributes

Throws
JsonParserError

if input cannot be parsed to JSON structure

def parse(input: Path): JsonStructure

Parses JSON structure from input.

Parses JSON structure from input.

Attributes

Throws
JsonParserError

if input cannot be parsed to JSON structure

def toBytes(value: JsonValue): Array[Byte]

Converts JSON value to UTF-8 encoded bytes.

Converts JSON value to UTF-8 encoded bytes.

Attributes

def toJson[T](value: T)(using output: JsonOutput[T]): JsonValue

Converts value to JSON value.

Converts value to JSON value.

Value parameters

output

converter

value

value

Attributes

def toPrettyPrint(value: JsonValue): String

Creates "pretty" print of JSON using 2-space indent.

Creates "pretty" print of JSON using 2-space indent.

Attributes

Note

If value is not a JSON structure, identation is not used and the output is equivalent to value.toString().

def toPrettyPrint(value: JsonValue, indent: String): String

Creates "pretty" print of JSON using supplied indent.

Creates "pretty" print of JSON using supplied indent.

Attributes

Note

If value is not a JSON structure, identation is not used and the output is equivalent to value.toString().