saison-0.1: Stream Aeson, fruity, spicy, well carbonated

Safe HaskellNone
LanguageHaskell2010

Saison.Decoding.Examples

Contents

Description

Various examples of using saison.

Synopsis

SomeValue

data SomeValue Source #

SomeValue is a dummy object. Decoding it from a JSON value always succeeds, but we don't preserve any information about that value.

If we decode a list [SomeValue], we can then count values in it.

This is an extreme example where saison approach shines.

instance FromTokens SomeValue where
    fromTokens = \toks -> SomeValue <$ skipValue toks

Constructors

SomeValue 
Instances
Eq SomeValue Source # 
Instance details

Defined in Saison.Decoding.Examples

Ord SomeValue Source # 
Instance details

Defined in Saison.Decoding.Examples

Show SomeValue Source # 
Instance details

Defined in Saison.Decoding.Examples

NFData SomeValue Source # 
Instance details

Defined in Saison.Decoding.Examples

Methods

rnf :: SomeValue -> () #

FromJSON SomeValue Source # 
Instance details

Defined in Saison.Decoding.Examples

Methods

parseJSON :: Value -> Parser SomeValue

parseJSONList :: Value -> Parser [SomeValue]

ToJSON SomeValue Source # 
Instance details

Defined in Saison.Decoding.Examples

Methods

toJSON :: SomeValue -> Value

toEncoding :: SomeValue -> Encoding

toJSONList :: [SomeValue] -> Value

toEncodingList :: [SomeValue] -> Encoding

FromTokens SomeValue Source # 
Instance details

Defined in Saison.Decoding.Examples

Laureates

newtype Laureates a Source #

Laureates a is a wrapper around a list of elements.

The laureate.json database is a json of form

{
  "laureates": [
     ...
  ]
}

This type parses the outer layer.

Constructors

Laureates 

Fields

Instances
Eq a => Eq (Laureates a) Source # 
Instance details

Defined in Saison.Decoding.Examples

Methods

(==) :: Laureates a -> Laureates a -> Bool #

(/=) :: Laureates a -> Laureates a -> Bool #

Show a => Show (Laureates a) Source # 
Instance details

Defined in Saison.Decoding.Examples

NFData a => NFData (Laureates a) Source # 
Instance details

Defined in Saison.Decoding.Examples

Methods

rnf :: Laureates a -> () #

FromJSON a => FromJSON (Laureates a) Source # 
Instance details

Defined in Saison.Decoding.Examples

Methods

parseJSON :: Value -> Parser (Laureates a)

parseJSONList :: Value -> Parser [Laureates a]

FromTokens a => FromTokens (Laureates a) Source #

This instance differs from aeson's, here we require that object has exactly one key: "laureates".

  • TODO: currently this instance is written manually. Separate ways to interpret record: lenient and strict.
Instance details

Defined in Saison.Decoding.Examples

data Laureate Source #

Almost complete information about a laureate. We skip "prizes" information.

Look at the implementaton of FromJSON and FromTokens instances, they don't look that much different.

Instances
Eq Laureate Source # 
Instance details

Defined in Saison.Decoding.Examples

Show Laureate Source # 
Instance details

Defined in Saison.Decoding.Examples

NFData Laureate Source # 
Instance details

Defined in Saison.Decoding.Examples

Methods

rnf :: Laureate -> () #

FromJSON Laureate Source # 
Instance details

Defined in Saison.Decoding.Examples

Methods

parseJSON :: Value -> Parser Laureate

parseJSONList :: Value -> Parser [Laureate]

FromTokens Laureate Source # 
Instance details

Defined in Saison.Decoding.Examples