hw-aeson-0.1.9.0: Convenience functions for Aeson
Safe HaskellSafe-Inferred
LanguageHaskell2010

HaskellWorks.Data.Aeson

Synopsis

Documentation

newtype JsonEndo a Source #

Constructors

JsonEndo 

Fields

Instances

Instances details
KeyValue a => KeyValue (JsonEndo a) Source # 
Instance details

Defined in HaskellWorks.Data.Aeson

Methods

(.=) :: ToJSON v => Key -> v -> JsonEndo a #

Monoid (JsonEndo a) Source # 
Instance details

Defined in HaskellWorks.Data.Aeson

Methods

mempty :: JsonEndo a #

mappend :: JsonEndo a -> JsonEndo a -> JsonEndo a #

mconcat :: [JsonEndo a] -> JsonEndo a #

Semigroup (JsonEndo a) Source # 
Instance details

Defined in HaskellWorks.Data.Aeson

Methods

(<>) :: JsonEndo a -> JsonEndo a -> JsonEndo a #

sconcat :: NonEmpty (JsonEndo a) -> JsonEndo a #

stimes :: Integral b => b -> JsonEndo a -> JsonEndo a #

newtype WithJsonKeyValues a Source #

For use with language extension DerivingVia. This derivation provides a ToJSON instance that delegates to the ToJsonKeyValues instance.

For example:

newtype MyType = MyType
  { myField :: Text
  } deriving J.ToJSON via WithJsonKeyValues MyType

Constructors

WithJsonKeyValues 

Fields

class ToJsonKeyValues a where Source #

Generate key values from a value of a type. This can be used in conjunction with WithJsonKeyValues to define a ToJSON instance without having to implement both toJSON and toEncoding, thereby reducing boilerplate.

For example:

instance ToJsonEncoding MyType where
  toJsonEncoding sv =
    [ "my_field" .!= sv ^. #myField
    ]

Methods

toJsonKeyValues :: (KeyValue kv, Monoid kv) => a -> [kv] Source #

objectEndo :: [JsonEndo Pair] -> Value Source #

Same as object except used in combination with .?= and .!= instead of .=.

For example:

toJSON o = objectEndo
  [ "mandatory" .!= o ^. the "mandatory"
  , "optional"  .?= o ^. the "optional"
  ]

(.?=) :: (KeyValue p, ToJSON v, Monoid p) => Key -> Maybe v -> p infixr 7 Source #

Render optional fields as missing in JSON output.

(.!=) :: (KeyValue kv, ToJSON v) => Key -> v -> kv infixr 7 Source #

Same as .=, but with lower precedence to work well with lens.