What is Aeson?
Aeson is the de-facto JSON library for Haskell — fast, well-typed, and supports automatic deriving of FromJSON and ToJSON instances from a Generic representation. Most Haskell production codebases (Yesod, Servant, Hasql-based services) depend on Aeson directly or transitively. The package is maintained on Hackage as aeson.
How does FromJSON / ToJSON work?
FromJSON is a typeclass with a parseJSON method that converts a Value (Aeson’s parsed JSON tree) into your data type — typically returning Either String YourType. ToJSON does the reverse with toJSON :: YourType -> Value. With deriving Generic, you can write instance FromJSON YourType (an empty instance) and Aeson uses GHC.Generics to derive the implementation at compile time.
How does Generic deriving work?
GHC.Generics provides a structural representation of a Haskell type at compile time. Aeson’s default FromJSON / ToJSON implementations are written in terms of that Generic representation, so any data type that derives Generic gets free JSON instances by writing instance FromJSON Foo and instance ToJSON Foo (no method bodies required). The {-# LANGUAGE DeriveGeneric #-} pragma enables the syntax.
How are field names mapped to JSON keys?
By default Aeson uses the Haskell field name verbatim as the JSON key. Because Haskell record field selectors are top-level functions, the generator prefixes them with the lowercased type name to avoid name clashes (e.g. rootId instead of id). To map back to the bare key id at JSON time, customize the encoding with genericParseJSON defaultOptions{fieldLabelModifier = drop 4} or by writing custom Aeson Options.
How are nested JSON objects modelled?
Each nested JSON object becomes its own data declaration with its own FromJSON/ToJSON instances. The parent type references the child type by name. Order is emitted so that nested types appear before parents reference them (Haskell does not strictly require this, but it improves readability).
How are JSON arrays handled?
A JSON array becomes [T] (Haskell list of T) where T is inferred from the first element. Arrays of strings become [String]; arrays of objects become [ChildType]. For arrays of mixed types use [Value] (Aeson’s untyped JSON value) and pattern-match at use site.
Is the JSON uploaded to your servers?
No. Conversion runs entirely in your browser via JavaScript. Open DevTools → Network and click Convert — no requests are made. Pasting JSON containing tokens or proprietary data never leaves your machine.
How do I parse a JSON string at runtime?
Use Data.Aeson.eitherDecode :: ByteString -> Either String Root from a lazy ByteString. For strict ByteString use eitherDecodeStrict. Pattern-match on Left err / Right value and propagate errors via your monad. The generator output works with all variants of the Aeson decode family.