ecluse:ecluse-core
Safe HaskellNone
LanguageGHC2021

Ecluse.Core.Json.Lenient

Description

Small lenient-decode primitives shared by every ecosystem's aeson wire decoders. Pure aeson support with no registry or package concept, so it sits beside the bounded selective-decode engine in Ecluse.Core.Json.Selective rather than in any one ecosystem's wire module:

  • lenientOptional reads an optional field, degrading a present-but-undecodable value to Nothing rather than failing the whole decode, so one poisoned advisory value cannot deny a whole document.
  • typeMismatchOneOf fails a permissive string-or-object decoder with a descriptive message that names the accepted shapes and the JSON kind actually found.
Synopsis

Documentation

lenientOptional :: FromJSON a => Object -> Key -> Parser (Maybe a) Source #

Decode an optional field leniently: an absent, null, or present-but-undecodable value all yield Nothing. Where (.:?) fails the whole decode on a present-but-wrong value, this degrades a hostile value (wrong-typed, fractional, or outside the target's range) to Nothing instead. Reserved for advisory fields, so one poisoned value cannot deny the whole document; a load-bearing field keeps (.:?)/(.:).

typeMismatchOneOf :: String -> Value -> Parser a Source #

Fail a lenient string-or-object decoder with a descriptive message, naming the accepted shapes and reporting what was actually found. Keeps the other -> branch of each tolerant instance to one readable line.