flix

0.73.0

Util.Json.FromJson

trait FromJson[a: Type]Source

A trait for types that can be decoded from a Json value.

Instances

instance FromJson[Json]Source
instance FromJson[Unit]Source
instance FromJson[Bool]Source
instance FromJson[String]Source
instance FromJson[Int8]Source

Integer-valued JSON numbers (e.g. 42, 42.0) decode; genuine fractions (e.g. 42.5) and out-of-range values error.

instance FromJson[Int16]Source

Integer-valued JSON numbers (e.g. 42, 42.0) decode; genuine fractions (e.g. 42.5) and out-of-range values error.

instance FromJson[Int32]Source

Integer-valued JSON numbers (e.g. 42, 42.0) decode; genuine fractions (e.g. 42.5) and out-of-range values error.

instance FromJson[Int64]Source

Integer-valued JSON numbers (e.g. 42, 42.0) decode; genuine fractions (e.g. 42.5) and out-of-range values error.

instance FromJson[BigInt]Source

Integer-valued JSON numbers (e.g. 42, 42.0) decode; genuine fractions (e.g. 42.5) error.

instance FromJson[BigDecimal]Source
instance FromJson[Float32]Source

Out-of-range values error; precision loss may occur within range.

instance FromJson[Float64]Source

Out-of-range values error; precision loss may occur within range.

instance FromJson[Option[a]] with FromJson[a]Source

JNull decodes to None; any other value is decoded with FromJson[a] and wrapped in Some. The path is left unchanged — Option does not introduce a structural step.

instance FromJson[Vector[a]] with FromJson[a]Source
instance FromJson[List[a]] with FromJson[a]Source
instance FromJson[Set[a]] with FromJson[a], Order[a]Source

Duplicate elements are deduplicated by Order[a]. The element type's path is threaded as Index(i) for any decode failure.

instance FromJson[Map[k, v]] with FromString[k], Order[k], FromJson[v]Source

Object keys are decoded via FromString[k]; a key that fails to parse errors with TypeMismatch("Map key") at path Key(stringKey). Value decode failures carry path Key(stringKey) followed by the inner path.

instance FromJson[(a1, a2)] with FromJson[a1], FromJson[a2]Source
instance FromJson[(a1, a2, a3)] with FromJson[a1], FromJson[a2], FromJson[a3]Source
instance FromJson[(a1, a2, a3, a4)] with FromJson[a1], FromJson[a2], FromJson[a3], FromJson[a4]Source
instance FromJson[(a1, a2, a3, a4, a5)] with FromJson[a1], FromJson[a2], FromJson[a3], FromJson[a4], FromJson[a5]Source
instance FromJson[(a1, a2, a3, a4, a5, a6)] with FromJson[a1], FromJson[a2], FromJson[a3], FromJson[a4], FromJson[a5], FromJson[a6]Source
instance FromJson[(a1, a2, a3, a4, a5, a6, a7)] with FromJson[a1], FromJson[a2], FromJson[a3], FromJson[a4], FromJson[a5], FromJson[a6], FromJson[a7]Source
instance FromJson[(a1, a2, a3, a4, a5, a6, a7, a8)] with FromJson[a1], FromJson[a2], FromJson[a3], FromJson[a4], FromJson[a5], FromJson[a6], FromJson[a7], FromJson[a8]Source
instance FromJson[(a1, a2, a3, a4, a5, a6, a7, a8, a9)] with FromJson[a1], FromJson[a2], FromJson[a3], FromJson[a4], FromJson[a5], FromJson[a6], FromJson[a7], FromJson[a8], FromJson[a9]Source
instance FromJson[(a1, a2, a3, a4, a5, a6, a7, a8, a9, a10)] with FromJson[a1], FromJson[a2], FromJson[a3], FromJson[a4], FromJson[a5], FromJson[a6], FromJson[a7], FromJson[a8], FromJson[a9], FromJson[a10]Source

Signatures

def fromJson(j: Json): Result[JsonError, a] with FromJson[a] Source

Module Definitions

def decodeAtIndex(i: Int32, j: Json): Result[JsonError, a] with FromJson[a] Source

Looks up index i in j, which must be a JArray, and decodes the element via FromJson[a].

If i is out of range, errors with MissingIndex(i) at the empty path. If the element is present but fails to decode, the inner error's path is prepended with Index(i).

def decodeAtKey(k: String, j: Json): Result[JsonError, a] with FromJson[a] Source

Looks up k in j and decodes the value via FromJson[a].

If k is absent, errors with MissingKey(k) at the empty path. If k is present but the value fails to decode, the inner error's path is prepended with Key(k).

def decodeAtKeyOpt(k: String, j: Json): Result[JsonError, Option[a]] with FromJson[a] Source

Looks up k in j and, if present, decodes the value via FromJson[a].

Returns Ok(None) if k is absent, Ok(Some(v)) if present and decodable, or the decode error otherwise.

def decodeAtPath(p: JsonPath, j: Json): Result[JsonError, a] with FromJson[a] Source

Looks up the value at p in j and decodes it via FromJson[a].

Navigation failures follow the same path/kind convention as getAtPath. If navigation succeeds and the leaf decoder fails, the leaf's own inner path (e.g. /0 from a failing Vector element) is appended to p, giving the full root-to-failure path.

def decodeAtPathOpt(p: JsonPath, j: Json): Result[JsonError, Option[a]] with FromJson[a] Source

Looks up the value at p in j and, if present, decodes it via FromJson[a].

Missing-key and missing-index failures along p yield Ok(None). Type-mismatch failures (a Key step into a non-object, or an Index step into a non-array) still error, since those signal a real shape disagreement. Leaf decode failures are reported with the full p-prefixed path.

def getAtKey(k: String, j: Json): Result[JsonError, Json] Source

Looks up k in j, which must be a JObject.

Returns the raw Json value at k, MissingKey(k) if k is absent, or TypeMismatch if j is not a JObject. Both errors carry the empty path (the failure is at the level of j itself).

def getAtKeyOpt(k: String, j: Json): Result[JsonError, Option[Json]] Source

Looks up k in j, which must be a JObject.

Returns Some(v) if present, None if absent, or TypeMismatch if j is not a JObject.

def getAtPath(p: JsonPath, j: Json): Result[JsonError, Json] Source

Walks p in j and returns the raw Json value at the leaf.

On failure the error's path points to the prefix of p that was successfully traversed — i.e. up to but not including the failing step. The failing step is reflected in the error's kind: MissingKey(k) for an absent object key, MissingIndex(i) for an out-of-range array index, and TypeMismatch for a step that descends into the wrong shape (e.g. a Key into a non-object).