APIJson.Field
Json.Field
The JSON field options and the string escaping both JSON derivers share.
Programs write the options as #[Json.Key …], #[Json.Skip], and
#[Json.Default …] through Json, which re-exports FieldOption. The
rest of this module serves derivers and decoders that must match what the
encoder writes.
FieldOption
type FieldOption = Key String | Skip | Default CodeSource
An option on a record field, read by the JSON derivers. Each may occur once per field, emitted keys must be unique, and options anywhere but on a record field are rejected. Violations fail at compile time, at the attribute.
Constructors
Skip
Skip : FieldOptionSource
Omit the field when encoding and ignore it when decoding. It requires
Default and cannot combine with Key.
Default
Default : Code -> FieldOptionSource
The value to use when decoding finds no key. The code is checked against the field’s type, keeps the scope it was written in, and runs only when the fallback is needed.
FieldSettings
type FieldSettings = { key : String , skip : Bool , fallback : Maybe Code , keySite : Maybe Site , skipSite : Maybe Site , defaultSite : Maybe Site }Source
One field’s options, collected and checked.
Fields
escapeChar
escapeChar : Char -> StringSource
The JSON escape for a character that cannot appear plainly in a string.
import Char
import Json.Field
Json.Field.escapeChar '"' == "\\\""
Json.Field.escapeChar '\n' == "\\n"
Json.Field.escapeChar (Maybe.withDefault 'x' (Char.fromCode 1)) == "\\u0001"
fieldSettings
fieldSettings : String -> Attributes -> FieldSettingsSource
The settings of the field name with these attributes, failing at compile
time on a repeated option or an invalid combination.
plainChar
plainChar : Char -> BoolSource
Whether a character appears unescaped in a JSON string.
quote
quote : String -> StringSource
A JSON string literal, quotes included.
import Json.Field
Json.Field.quote "a\"b" == "\"a\\\"b\""
validateJSONSchema
validateJSONSchema : TypeInfo -> ()Source
Checks every JSON option on a type: unique keys among emitted record fields, and no options anywhere but on record fields.
