Json

object Json

Provides JSON utilities.

import little.json.*
import little.json.Implicits.given
import scala.language.implicitConversions

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

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

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

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

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

// Convert value to JSON object
val nobody = Json.toJson(User(65534, "nobody"))
class Object
trait Matchable
class Any

Value members

Concrete methods

def arr(values: JsonValue*): JsonArray

Creates JSON array with supplied values.

Creates JSON array with supplied values.

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

Creates JSON object with supplied fields.

Creates JSON object with supplied fields.

def parse(text: String): JsonStructure

Parses JSON structure from text.

Parses JSON structure from text.

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

Parses JSON structure from bytes.

Parses JSON structure from bytes.

def parse(input: Reader): JsonStructure

Parses JSON structure from input.

Parses JSON structure from input.

Note

Closes input on return.

def parse(input: InputStream): JsonStructure

Parses JSON structure from input.

Parses JSON structure from input.

Note

Closes input on return.

def parse(input: File): JsonStructure

Parses JSON structure from input.

Parses JSON structure from input.

def parse(input: Path): JsonStructure

Parses JSON structure from input.

Parses JSON structure from input.

def toBytes(json: JsonStructure): Array[Byte]

Converts JSON structure to UTF-8 encoded bytes.

Converts JSON structure to UTF-8 encoded bytes.

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

Converts value to JSON value.

Converts value to JSON value.

Value Params
convert

output converter

value

value

def toPrettyPrint(json: JsonStructure): String

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

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

def toPrettyPrint(json: JsonStructure, indent: String): String

Creates "pretty" print of JSON using supplied indent.

Creates "pretty" print of JSON using supplied indent.