Util.Json.FromJson
trait FromJson[a: Type]SourceA trait for types that can be decoded from a Json value.
Instances
Integer-valued JSON numbers (e.g. 42, 42.0) decode; genuine fractions
(e.g. 42.5) and out-of-range values error.
Integer-valued JSON numbers (e.g. 42, 42.0) decode; genuine fractions
(e.g. 42.5) and out-of-range values error.
Integer-valued JSON numbers (e.g. 42, 42.0) decode; genuine fractions
(e.g. 42.5) and out-of-range values error.
Integer-valued JSON numbers (e.g. 42, 42.0) decode; genuine fractions
(e.g. 42.5) and out-of-range values error.
Integer-valued JSON numbers (e.g. 42, 42.0) decode; genuine fractions
(e.g. 42.5) error.
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.
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]SourceObject 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.
Signatures
Module Definitions
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).
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).
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.
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.
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]
SourceLooks 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]]
SourceLooks 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]
SourceWalks 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).