Implicits

object Implicits

Provides extension methods and implicit conversions.

class Object
trait Matchable
class Any

Givens

Givens

given arrayToJsonArray[T](using val convert: JsonOutput[T]): JsonOutput[Array[T]]

Converts Array to JsonArray.

Converts Array to JsonArray.

Converts BigDecimal to JsonNumber.

Converts BigDecimal to JsonNumber.

Converts BigInt to JsonNumber.

Converts BigInt to JsonNumber.

Converts Boolean to JsonBoolean.

Converts Boolean to JsonBoolean.

Converts Byte to JsonNumber.

Converts Byte to JsonNumber.

Converts Double to JsonNumber.

Converts Double to JsonNumber.

given eitherToJsonValue[A, B, M <: ([A, B] =>> Either[A, B])](using val left: JsonOutput[A])(using val right: JsonOutput[B]): JsonOutput[M[A, B]]

Converts Right to JsonValue using right converter or converts Left using left.

Converts Right to JsonValue using right converter or converts Left using left.

given failureToJsonNull: JsonOutput[Failure[_]]

Converts Failure to JsonNull.

Converts Failure to JsonNull.

Converts Float to JsonNumber.

Converts Float to JsonNumber.

Converts Int to JsonNumber.

Converts Int to JsonNumber.

given iterableToJsonArray[T, M <: ([T] =>> Iterable[T])](using val convert: JsonOutput[T]): JsonOutput[M[T]]

Converts Iterable to JsonArray.

Converts Iterable to JsonArray.

given jsonValueToBigDecimal: JsonInput[BigDecimal]

Converts JsonValue to BigDecimal.

Converts JsonValue to BigDecimal.

Converts JsonValue to BigInt.

Converts JsonValue to BigInt.

given jsonValueToBoolean: JsonInput[Boolean]

Converts JsonValue to Boolean.

Converts JsonValue to Boolean.

Converts JsonValue to Byte.

Converts JsonValue to Byte.

given jsonValueToCollection[T, M[T]](using val convert: JsonInput[T])(using val factory: Factory[T, M[T]]): JsonInput[M[T]]

Converts JsonValue to collection of converted values.

Converts JsonValue to collection of converted values.

Converts JsonValue to Double.

Converts JsonValue to Double.

given jsonValueToEither[A, B](using val left: JsonInput[A])(using val right: JsonInput[B]): JsonInput[Either[A, B]]

Converts JsonValue to Right using right converter or to Left using left if right is unsuccessful.

Converts JsonValue to Right using right converter or to Left using left if right is unsuccessful.

Converts JsonValue to Float.

Converts JsonValue to Float.

Converts JsonValue to Int.

Converts JsonValue to Int.

Casts JsonValue to JsonArray.

Casts JsonValue to JsonArray.

Casts JsonValue to JsonBoolean.

Casts JsonValue to JsonBoolean.

Casts JsonValue to JsonNull.

Casts JsonValue to JsonNull.

Casts JsonValue to JsonNumber.

Casts JsonValue to JsonNumber.

Casts JsonValue to JsonObject.

Casts JsonValue to JsonObject.

Casts JsonValue to JsonString.

Casts JsonValue to JsonString.

Returns JsonValue as is.

Returns JsonValue as is.

This instance is required to perform actions such as the following:

import little.json.{ Json, JsonValue }
import little.json.Implicits.given

import scala.language.implicitConversions

val json = Json.obj("values" -> Json.arr("abc", 123, true))

// Requires jsonValueToJsonValue
val list = json("values").as[List[JsonValue]]

Converts JsonValue to Long.

Converts JsonValue to Long.

given jsonValueToOption[T](using val convert: JsonInput[T]): JsonInput[Option[T]]

Converts JsonValue to Some or returns None if value is JsonNull.

Converts JsonValue to Some or returns None if value is JsonNull.

Converts JsonValue to Short.

Converts JsonValue to Short.

Converts JsonValue to String.

Converts JsonValue to String.

given jsonValueToTry[T](using val convert: JsonInput[T]): JsonInput[Try[T]]

Converts JsonValue to Success or returns Failure if unsuccessful.

Converts JsonValue to Success or returns Failure if unsuccessful.

given leftToJsonValue[T](using val convert: JsonOutput[T]): JsonOutput[Left[T, _]]

Converts Left to JsonValue.

Converts Left to JsonValue.

Converts Long to JsonNumber.

Converts Long to JsonNumber.

Converts None to JsonNull.

Converts None to JsonNull.

given optionToJsonValue[T, M <: ([T] =>> Option[T])](using val convert: JsonOutput[T]): JsonOutput[M[T]]

Converts Some to JsonValue or returns JsonNull if None.

Converts Some to JsonValue or returns JsonNull if None.

given rightToJsonValue[T](using val convert: JsonOutput[T]): JsonOutput[Right[_, T]]

Converts Right to JsonValue.

Converts Right to JsonValue.

Converts Short to JsonNumber.

Converts Short to JsonNumber.

Converts String to JsonString.

Converts String to JsonString.

given tryToJsonValue[T, M <: ([T] =>> Try[T])](using val convert: JsonOutput[T]): JsonOutput[M[T]]

Converts Success to JsonValue or returns JsonNull if Failure.

Converts Success to JsonValue or returns JsonNull if Failure.

given tupleToJsonField[T](using val convert: JsonOutput[T]): Conversion[(String, T), (String, JsonValue)]

Converts (String, T) to (String, JsonValue).

Converts (String, T) to (String, JsonValue).

Extensions

Extensions

extension (json: JsonValue)
@targetName("at")
def \(name: String): JsonValue

Gets value in JSON object.

Gets value in JSON object.

Value Params
name

field name

Throws
ClassCastException

if not JsonObject

@targetName("at")
def \(index: Int): JsonValue

Gets value in JSON array.

Gets value in JSON array.

Value Params
index

array index

Throws
ClassCastException

if not JsonArray

@targetName("collect")
def \\(name: String): Seq[JsonValue]

Collects values with given field name while traversing nested objects and arrays.

Collects values with given field name while traversing nested objects and arrays.

import little.json.Json
import little.json.Implicits.{ *, given }

val json = Json.parse("""{
 "node": {
   "name": "localhost",
   "users": [
     { "id": 0,    "name": "root" },
     { "id": 1000, "name": "jza"  }
   ]
 }
}""")

val names = (json \\ "name").map(_.as[String])

assert { names == Seq("localhost", "root", "jza") }
Value Params
name

field name