JsonDecoder

org.sigilaris.core.codec.json.JsonDecoder
See theJsonDecoder companion object
trait JsonDecoder[A]

Type class for decoding the core JsonValue AST into Scala values.

Decoders use JsonConfig to interpret field naming, discriminator strategy, null/absent semantics, and big number representations.

Combinators map/emap help build validated or dependent decoders; derived provides automatic derivation for products and sums.

Attributes

See also

JsonEncoder for the inverse operation

JsonCodec for bidirectional encoding and decoding

JsonConfig for configuration options

Note

Decoding validates structure and types. Failures return org.sigilaris.core.failure.DecodeFailure with descriptive error messages.

Example
 case class User(name: String, age: Int) derives JsonDecoder
 val json = JsonValue.obj("name" -> JString("Alice"), "age" -> JNumber(30))
 val user = JsonDecoder[User].decode(json)
Companion
object
Source
JsonDecoder.scala
Graph
Supertypes
class Object
trait Matchable
class Any
Self type

Members list

Value members

Abstract methods

def decode(json: JsonValue): Either[DecodeFailure, A]

Decodes a JSON value to a Scala value.

Decodes a JSON value to a Scala value.

Value parameters

json

the JSON value to decode

Attributes

Returns

either a decode failure or the decoded value

Source
JsonDecoder.scala

Concrete methods

def emap[B](f: A => Either[DecodeFailure, B]): JsonDecoder[B]

Creates a new decoder by applying a validation function after decoding.

Creates a new decoder by applying a validation function after decoding.

Value parameters

f

the validation function

Attributes

Returns

a new decoder for type B

Example
 val positiveInt = JsonDecoder[Int].emap { n =>
   if n > 0 then Right(n) else Left(DecodeFailure("Must be positive"))
 }
Source
JsonDecoder.scala
def map[B](f: A => B): JsonDecoder[B]

Creates a new decoder by applying a function after decoding.

Creates a new decoder by applying a function after decoding.

Value parameters

f

the postprocessing function

Attributes

Returns

a new decoder for type B

Example
 val intDecoder: JsonDecoder[Int] = JsonDecoder[Int]
 val evenDecoder                  = intDecoder.emap { n =>
   if n % 2 == 0 then Right(n) else Left(DecodeFailure("Not even"))
 }
Source
JsonDecoder.scala