JsonOutput

trait JsonOutput[T] extends Conversion[T, JsonValue]

Defines JSON output conversion.

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

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

// Define how to convert User to JsonValue
given userToJson: JsonOutput[User] with
 def apply(u: User) = Json.obj("id" -> u.id, "name" -> u.name)

val users = Json.arr(User(0, "root"), User(1000, "jza"))
assert { users(0) == Json.obj("id" -> 0, "name" -> "root") }
assert { users(1) == Json.obj("id" -> 1000, "name" -> "jza") }
See also
class Conversion[T, JsonValue]
trait T => JsonValue
class Object
trait Matchable
class Any

Value members

Abstract methods

def apply(value: T): JsonValue

Converts to JSON value.

Converts to JSON value.

Inherited methods

@unspecialized
def andThen[A](g: JsonValue => A): T => A
Inherited from
Function1
@unspecialized
def compose[A](g: A => T): A => JsonValue
Inherited from
Function1
override def toString(): String
Definition Classes
Function1 -> Any
Inherited from
Function1

Extensions

Inherited extensions

extension (x: T)

x.convert converts a value x of type T to type U

x.convert converts a value x of type T to type U

Inherited from
Conversion