JsonInput

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

Defines JSON input conversion.

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

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

// Define how to convert JsonValue to User
given jsonToUser: JsonInput[User] with
 def apply(json: JsonValue) = User(json("id"), json("name"))

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

Value members

Abstract methods

def apply(value: JsonValue): T

Converts JSON value.

Converts JSON value.

Inherited methods

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

Extensions

Inherited extensions

extension (x: T)
def convert: 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