{-# LANGUAGE OverloadedStrings, DeriveGeneric #-}importData.AesonimportGHC.GenericsdataProfile=Profile{age::Int,isNice::Bool}deriving(Show,Generic)dataUser=User{id::Int,name::String,profile::Profile}deriving(Show,Generic)instanceFromJSONProfileinstanceToJSONProfileinstanceFromJSONUserinstanceToJSONUsermain=doletprofile=Profile29Trueletuser=User1"Kuba"profileputStrLn$showuser-- encode will give you back ByteStringletjson=encodeuserputStrLn$showjson-- decode will give you back MaybeletparsedUser=decodejson::MaybeUsercaseparsedUserofJustnewUser->putStrLn$shownewUserNothing->putStrLn"Sorry mate this is not happening"
Here i made shortest possible example to show off how you can work with Aeson. First of all if you will use Generics you don’t have to write real implementation of ToJSON and FromJSON GHC will do this or you!
Only thing to remember is that encode will give you back ByteString and decode will give you Maybe A and thats it.
You always can fallback to normal way of describing FromJSON and ToJSON :)