xlsx-tabular-0.1.1: Xlsx table decode utility

Codec.Xlsx.Util.Tabular.Imports

Description

Internal imports.

Synopsis

Documentation

join :: Monad m => m (m a) -> m a #

The join function is the conventional monad join operator. It is used to remove one level of monadic structure, projecting its bound argument into the outer level.

find :: Foldable t => (a -> Bool) -> t a -> Maybe a #

The find function takes a predicate and a structure and returns the leftmost element of the structure matching the predicate, or Nothing if there is no such element.

fromMaybe :: a -> Maybe a -> a #

The fromMaybe function takes a default value and and Maybe value. If the Maybe is Nothing, it returns the default values; otherwise, it returns the value contained in the Maybe.

Examples

Basic usage:

>>> fromMaybe "" (Just "Hello, World!")
"Hello, World!"

>>> fromMaybe "" Nothing
""


Read an integer from a string using readMaybe. If we fail to parse an integer, we want to return 0 by default:

>>> import Text.Read ( readMaybe )
>>> fromMaybe 0 (readMaybe "5")
5
>>> fromMaybe 0 (readMaybe "")
0


isJust :: Maybe a -> Bool #

The isJust function returns True iff its argument is of the form Just _.

Examples

Basic usage:

>>> isJust (Just 3)
True

>>> isJust (Just ())
True

>>> isJust Nothing
False


Only the outer constructor is taken into consideration:

>>> isJust (Just Nothing)
True


keys :: Map k a -> [k] #

O(n). Return all keys of the map in ascending order. Subject to list fusion.

keys (fromList [(5,"a"), (3,"b")]) == [3,5]
keys empty == []

(<$>) :: Functor f => (a -> b) -> f a -> f b infixl 4 # An infix synonym for fmap. The name of this operator is an allusion to $. Note the similarities between their types:

 ($) :: (a -> b) -> a -> b (<$>) :: Functor f => (a -> b) -> f a -> f b

Whereas $ is function application, <$> is function application lifted over a Functor.

Examples

Convert from a Maybe Int to a Maybe String using show:

>>> show <$> Nothing Nothing >>> show <$> Just 3
Just "3"


Convert from an Either Int Int to an Either Int String using show:

>>> show <$> Left 17 Left 17 >>> show <$> Right 17
Right "17"


Double each element of a list:

>>> (*2) <$> [1,2,3] [2,4,6]  Apply even to the second element of a pair: >>> even <$> (2,2)
(2,True)


(<*>) :: Applicative f => forall a b. f (a -> b) -> f a -> f b #

Sequential application.

view :: MonadReader s m => Getting a s a -> m a #

View the value pointed to by a Getter, Iso or Lens or the result of folding over all the results of a Fold or Traversal that points at a monoidal value.

view . to ≡ id

>>> view (to f) a
f a

>>> view _2 (1,"hello")
"hello"

>>> view (to succ) 5
6

>>> view (_2._1) ("hello",("world","!!!"))
"world"


As view is commonly used to access the target of a Getter or obtain a monoidal summary of the targets of a Fold, It may be useful to think of it as having one of these more restricted signatures:

view ::             Getter s a     -> s -> a
view :: Monoid m => Fold s m       -> s -> m
view ::             Iso' s a       -> s -> a
view ::             Lens' s a      -> s -> a
view :: Monoid m => Traversal' s m -> s -> m


In a more general setting, such as when working with a Monad transformer stack you can use:

view :: MonadReader s m             => Getter s a     -> m a
view :: (MonadReader s m, Monoid a) => Fold s a       -> m a
view :: MonadReader s m             => Iso' s a       -> m a
view :: MonadReader s m             => Lens' s a      -> m a
view :: (MonadReader s m, Monoid a) => Traversal' s a -> m a


to :: (Profunctor p, Contravariant f, Functor f) => (s -> a) -> Optic' * * p f s a #

Build an (index-preserving) Getter from an arbitrary Haskell function.

to f . to g ≡ to (g . f)

a ^. to f ≡ f a

>>> a ^.to f
f a

>>> ("hello","world")^.to snd
"world"

>>> 5^.to succ
6

>>> (0, -5)^._2.to abs
5

to :: (s -> a) -> IndexPreservingGetter s a


contains :: Contains m => Index m -> Lens' m Bool #

>>> IntSet.fromList [1,2,3,4] ^. contains 3
True

>>> IntSet.fromList [1,2,3,4] ^. contains 5
False

>>> IntSet.fromList [1,2,3,4] & contains 3 .~ False
fromList [1,2,4]


(^.) :: s -> Getting a s a -> a infixl 8 #

View the value pointed to by a Getter or Lens or the result of folding over all the results of a Fold or Traversal that points at a monoidal values.

This is the same operation as view with the arguments flipped.

The fixity and semantics are such that subsequent field accesses can be performed with (.).

>>> (a,b)^._2
b

>>> ("hello","world")^._2
"world"

>>> import Data.Complex
>>> ((0, 1 :+ 2), 3)^._1._2.to magnitude
2.23606797749979

(^.) ::             s -> Getter s a     -> a
(^.) :: Monoid m => s -> Fold s m       -> m
(^.) ::             s -> Iso' s a       -> a
(^.) ::             s -> Lens' s a      -> a
(^.) :: Monoid m => s -> Traversal' s m -> m


(^?) :: s -> Getting (First a) s a -> Maybe a infixl 8 #

Perform a safe head of a Fold or Traversal or retrieve Just the result from a Getter or Lens.

When using a Traversal as a partial Lens, or a Fold as a partial Getter this can be a convenient way to extract the optional value.

Note: if you get stack overflows due to this, you may want to use firstOf instead, which can deal more gracefully with heavily left-biased trees.

>>> Left 4 ^?_Left
Just 4

>>> Right 4 ^?_Left
Nothing

>>> "world" ^? ix 3
Just 'l'

>>> "world" ^? ix 20
Nothing

(^?) ≡ flip preview

(^?) :: s -> Getter s a     -> Maybe a
(^?) :: s -> Fold s a       -> Maybe a
(^?) :: s -> Lens' s a      -> Maybe a
(^?) :: s -> Iso' s a       -> Maybe a
(^?) :: s -> Traversal' s a -> Maybe a


(.~) :: ASetter s t a b -> b -> s -> t infixr 4 #

Replace the target of a Lens or all of the targets of a Setter or Traversal with a constant value.

This is an infix version of set, provided for consistency with (.=).

f <$ a ≡ mapped .~ f $ a

>>> (a,b,c,d) & _4 .~ e
(a,b,c,e)

>>> (42,"world") & _1 .~ "hello"
("hello","world")

>>> (a,b) & both .~ c
(c,c)

(.~) :: Setter s t a b    -> b -> s -> t
(.~) :: Iso s t a b       -> b -> s -> t
(.~) :: Lens s t a b      -> b -> s -> t
(.~) :: Traversal s t a b -> b -> s -> t


(?~) :: ASetter s t a (Maybe b) -> b -> s -> t infixr 4 #

Set the target of a Lens, Traversal or Setter to Just a value.

l ?~ t ≡ set l (Just t)

>>> Nothing & id ?~ a
Just a

>>> Map.empty & at 3 ?~ x
fromList [(3,x)]

(?~) :: Setter s t a (Maybe b)    -> b -> s -> t
(?~) :: Iso s t a (Maybe b)       -> b -> s -> t
(?~) :: Lens s t a (Maybe b)      -> b -> s -> t
(?~) :: Traversal s t a (Maybe b) -> b -> s -> t


(&) :: a -> (a -> b) -> b infixl 1 #

& is a reverse application operator. This provides notational convenience. Its precedence is one higher than that of the forward application operator $, which allows & to be nested in $.

Since: 4.8.0.0

_1 :: Field1 s t a b => Lens s t a b #

Access the 1st field of a tuple (and possibly change its type).

>>> (1,2)^._1
1

>>> _1 .~ "hello" $(1,2) ("hello",2)  >>> (1,2) & _1 .~ "hello" ("hello",2)  >>> _1 putStrLn ("hello","world") hello ((),"world")  This can also be used on larger tuples as well: >>> (1,2,3,4,5) & _1 +~ 41 (42,2,3,4,5)  _1 :: Lens (a,b) (a',b) a a' _1 :: Lens (a,b,c) (a',b,c) a a' _1 :: Lens (a,b,c,d) (a',b,c,d) a a' ... _1 :: Lens (a,b,c,d,e,f,g,h,i) (a',b,c,d,e,f,g,h,i) a a'  _2 :: Field2 s t a b => Lens s t a b # Access the 2nd field of a tuple. >>> _2 .~ "hello"$ (1,(),3,4)
(1,"hello",3,4)

>>> (1,2,3,4) & _2 *~ 3
(1,6,3,4)

>>> _2 print (1,2)
2
(1,())

anyOf _2 :: (s -> Bool) -> (a, s) -> Bool
traverse . _2 :: (Applicative f, Traversable t) => (a -> f b) -> t (s, a) -> f (t (s, b))
foldMapOf (traverse . _2) :: (Traversable t, Monoid m) => (s -> m) -> t (b, s) -> m


_Right :: (Choice p, Applicative f) => p a (f b) -> p (Either c a) (f (Either c b)) #

This Prism provides a Traversal for tweaking the Right half of an Either:

>>> over _Right (+1) (Left 2)
Left 2

>>> over _Right (+1) (Right 2)
Right 3

>>> Right "hello" ^._Right
"hello"

>>> Left "hello" ^._Right :: [Double]
[]


It also can be turned around to obtain the embedding into the Right half of an Either:

>>> _Right # 5
Right 5

>>> 5^.re _Right
Right 5


data Text :: * #

A space efficient, packed, unboxed Unicode text type.

Instances

 MethodstoJSON :: Text -> Value #toJSONList :: [Text] -> Value #toEncodingList :: [Text] -> Encoding # Methods(.=) :: ToJSON v => Text -> v -> Pair # Methods Methods Methods Methods type Item Text type Item Text = Char type Index Text type Index Text = Int type IxValue Text type IxValue Text = Char

data IntSet :: * #

A set of integers.

Instances

 Associated Typestype Item IntSet :: * # MethodsfromList :: [Item IntSet] -> IntSet #fromListN :: Int -> [Item IntSet] -> IntSet #toList :: IntSet -> [Item IntSet] # Methods(==) :: IntSet -> IntSet -> Bool #(/=) :: IntSet -> IntSet -> Bool # Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> IntSet -> c IntSet #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c IntSet #dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c IntSet) #dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c IntSet) #gmapT :: (forall b. Data b => b -> b) -> IntSet -> IntSet #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> IntSet -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> IntSet -> r #gmapQ :: (forall d. Data d => d -> u) -> IntSet -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> IntSet -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> IntSet -> m IntSet #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> IntSet -> m IntSet #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> IntSet -> m IntSet # Methods(<) :: IntSet -> IntSet -> Bool #(<=) :: IntSet -> IntSet -> Bool #(>) :: IntSet -> IntSet -> Bool #(>=) :: IntSet -> IntSet -> Bool #max :: IntSet -> IntSet -> IntSet #min :: IntSet -> IntSet -> IntSet # Methods MethodsshowsPrec :: Int -> IntSet -> ShowS #showList :: [IntSet] -> ShowS # Methods(<>) :: IntSet -> IntSet -> IntSet #stimes :: Integral b => b -> IntSet -> IntSet # Methodsmconcat :: [IntSet] -> IntSet # MethodstoJSONList :: [IntSet] -> Value #toEncodingList :: [IntSet] -> Encoding # Methods Methodsrnf :: IntSet -> () # Methods Methods Methods type Item IntSet type Item IntSet = Key type Index IntSet type Index IntSet = Int type IxValue IntSet type IxValue IntSet = ()

fromList :: [Key] -> IntSet #

O(n*min(n,W)). Create a set from a list of integers.

class FromJSON a where #

A type that can be converted from JSON, with the possibility of failure.

In many cases, you can get the compiler to generate parsing code for you (see below). To begin, let's cover writing an instance by hand.

There are various reasons a conversion could fail. For example, an Object could be missing a required key, an Array could be of the wrong size, or a value could be of an incompatible type.

The basic ways to signal a failed conversion are as follows:

• empty and mzero work, but are terse and uninformative
• fail yields a custom error message
• typeMismatch produces an informative message for cases when the value encountered is not of the expected type

An example type and instance:

-- Allow ourselves to write Text literals.
{-# LANGUAGE OverloadedStrings #-}

data Coord = Coord { x :: Double, y :: Double }

instance FromJSON Coord where
parseJSON (Object v) = Coord    <\$>
v .: "x" <*>
v .: "y"

-- We do not expect a non-Object value here.
-- We could use mzero to fail, but typeMismatch
-- gives a much more informative error message.
parseJSON invalid    = typeMismatch "Coord" invalid


Instead of manually writing your FromJSON instance, there are two options to do it automatically:

• Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so will probably be more efficient than the following two options:
• The compiler can provide a default generic implementation for parseJSON.

To use the second, simply add a deriving Generic clause to your datatype and declare a FromJSON instance for your datatype without giving a definition for parseJSON.

For example, the previous example can be simplified to just:

{-# LANGUAGE DeriveGeneric #-}

import GHC.Generics

data Coord = Coord { x :: Double, y :: Double } deriving Generic

instance FromJSON Coord


If DefaultSignatures doesn't give exactly the results you want, you can customize the generic decoding with only a tiny amount of effort, using genericParseJSON with your preferred Options:

instance FromJSON Coord where
parseJSON = genericParseJSON defaultOptions


Methods

Instances

 Methods Methods Methods Methods Methods Methods Methods Methods Methods WARNING: Only parse Integers from trusted input since an attacker could easily fill up the memory of the target system by specifying a scientific number with a big exponent like 1e1000000000. Methods Methods Methods Methods Methods Methods Methods FromJSON () MethodsparseJSON :: Value -> Parser () #parseJSONList :: Value -> Parser [()] # Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods Methods WARNING: Only parse lengths of time from trusted input since an attacker could easily fill up the memory of the target system by specifying a scientific number with a big exponent like 1e1000000000. Methods Methods FromJSON a => FromJSON [a] MethodsparseJSON :: Value -> Parser [a] #parseJSONList :: Value -> Parser [[a]] # FromJSON a => FromJSON (Maybe a) MethodsparseJSON :: Value -> Parser (Maybe a) # (FromJSON a, Integral a) => FromJSON (Ratio a) MethodsparseJSON :: Value -> Parser (Ratio a) # FromJSON a => FromJSON (Identity a) Methods FromJSON a => FromJSON (Min a) MethodsparseJSON :: Value -> Parser (Min a) #parseJSONList :: Value -> Parser [Min a] # FromJSON a => FromJSON (Max a) MethodsparseJSON :: Value -> Parser (Max a) #parseJSONList :: Value -> Parser [Max a] # FromJSON a => FromJSON (First a) MethodsparseJSON :: Value -> Parser (First a) # FromJSON a => FromJSON (Last a) MethodsparseJSON :: Value -> Parser (Last a) # Methods FromJSON a => FromJSON (Option a) MethodsparseJSON :: Value -> Parser (Option a) # FromJSON a => FromJSON (NonEmpty a) Methods HasResolution a => FromJSON (Fixed a) WARNING: Only parse fixed-precision numbers from trusted input since an attacker could easily fill up the memory of the target system by specifying a scientific number with a big exponent like 1e1000000000. MethodsparseJSON :: Value -> Parser (Fixed a) # FromJSON a => FromJSON (Dual a) MethodsparseJSON :: Value -> Parser (Dual a) # FromJSON a => FromJSON (First a) MethodsparseJSON :: Value -> Parser (First a) # FromJSON a => FromJSON (Last a) MethodsparseJSON :: Value -> Parser (Last a) # FromJSON a => FromJSON (IntMap a) MethodsparseJSON :: Value -> Parser (IntMap a) # FromJSON v => FromJSON (Tree v) MethodsparseJSON :: Value -> Parser (Tree v) # FromJSON a => FromJSON (Seq a) MethodsparseJSON :: Value -> Parser (Seq a) #parseJSONList :: Value -> Parser [Seq a] # (Ord a, FromJSON a) => FromJSON (Set a) MethodsparseJSON :: Value -> Parser (Set a) #parseJSONList :: Value -> Parser [Set a] # FromJSON a => FromJSON (DList a) MethodsparseJSON :: Value -> Parser (DList a) # FromJSON a => FromJSON (Vector a) MethodsparseJSON :: Value -> Parser (Vector a) # (Prim a, FromJSON a) => FromJSON (Vector a) MethodsparseJSON :: Value -> Parser (Vector a) # (Storable a, FromJSON a) => FromJSON (Vector a) MethodsparseJSON :: Value -> Parser (Vector a) # (Vector Vector a, FromJSON a) => FromJSON (Vector a) MethodsparseJSON :: Value -> Parser (Vector a) # (Eq a, Hashable a, FromJSON a) => FromJSON (HashSet a) MethodsparseJSON :: Value -> Parser (HashSet a) # (FromJSON a, FromJSON b) => FromJSON (Either a b) MethodsparseJSON :: Value -> Parser (Either a b) #parseJSONList :: Value -> Parser [Either a b] # (FromJSON a, FromJSON b) => FromJSON (a, b) MethodsparseJSON :: Value -> Parser (a, b) #parseJSONList :: Value -> Parser [(a, b)] # (FromJSON v, FromJSONKey k, Eq k, Hashable k) => FromJSON (HashMap k v) MethodsparseJSON :: Value -> Parser (HashMap k v) #parseJSONList :: Value -> Parser [HashMap k v] # (FromJSONKey k, Ord k, FromJSON v) => FromJSON (Map k v) MethodsparseJSON :: Value -> Parser (Map k v) #parseJSONList :: Value -> Parser [Map k v] # FromJSON (Proxy k a) MethodsparseJSON :: Value -> Parser (Proxy k a) #parseJSONList :: Value -> Parser [Proxy k a] # (FromJSON a, FromJSON b, FromJSON c) => FromJSON (a, b, c) MethodsparseJSON :: Value -> Parser (a, b, c) #parseJSONList :: Value -> Parser [(a, b, c)] # FromJSON a => FromJSON (Const k a b) MethodsparseJSON :: Value -> Parser (Const k a b) #parseJSONList :: Value -> Parser [Const k a b] # FromJSON b => FromJSON (Tagged k a b) MethodsparseJSON :: Value -> Parser (Tagged k a b) #parseJSONList :: Value -> Parser [Tagged k a b] # (FromJSON a, FromJSON b, FromJSON c, FromJSON d) => FromJSON (a, b, c, d) MethodsparseJSON :: Value -> Parser (a, b, c, d) #parseJSONList :: Value -> Parser [(a, b, c, d)] # (FromJSON1 f, FromJSON1 g, FromJSON a) => FromJSON (Sum * f g a) MethodsparseJSON :: Value -> Parser (Sum * f g a) #parseJSONList :: Value -> Parser [Sum * f g a] # (FromJSON1 f, FromJSON1 g, FromJSON a) => FromJSON (Product * f g a) MethodsparseJSON :: Value -> Parser (Product * f g a) #parseJSONList :: Value -> Parser [Product * f g a] # (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e) => FromJSON (a, b, c, d, e) MethodsparseJSON :: Value -> Parser (a, b, c, d, e) #parseJSONList :: Value -> Parser [(a, b, c, d, e)] # (FromJSON1 f, FromJSON1 g, FromJSON a) => FromJSON (Compose * * f g a) MethodsparseJSON :: Value -> Parser (Compose * * f g a) #parseJSONList :: Value -> Parser [Compose * * f g a] # (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f) => FromJSON (a, b, c, d, e, f) MethodsparseJSON :: Value -> Parser (a, b, c, d, e, f) #parseJSONList :: Value -> Parser [(a, b, c, d, e, f)] # (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g) => FromJSON (a, b, c, d, e, f, g) MethodsparseJSON :: Value -> Parser (a, b, c, d, e, f, g) #parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g)] # (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h) => FromJSON (a, b, c, d, e, f, g, h) MethodsparseJSON :: Value -> Parser (a, b, c, d, e, f, g, h) #parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h)] # (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i) => FromJSON (a, b, c, d, e, f, g, h, i) MethodsparseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i) #parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i)] # (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j) => FromJSON (a, b, c, d, e, f, g, h, i, j) MethodsparseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i, j) #parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i, j)] # (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k) => FromJSON (a, b, c, d, e, f, g, h, i, j, k) MethodsparseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i, j, k) #parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k)] # (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l) => FromJSON (a, b, c, d, e, f, g, h, i, j, k, l) MethodsparseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, l) #parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, l)] # (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l, FromJSON m) => FromJSON (a, b, c, d, e, f, g, h, i, j, k, l, m) MethodsparseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, l, m) #parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, l, m)] # (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l, FromJSON m, FromJSON n) => FromJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n) MethodsparseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, l, m, n) #parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, l, m, n)] # (FromJSON a, FromJSON b, FromJSON c, FromJSON d, FromJSON e, FromJSON f, FromJSON g, FromJSON h, FromJSON i, FromJSON j, FromJSON k, FromJSON l, FromJSON m, FromJSON n, FromJSON o) => FromJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) MethodsparseJSON :: Value -> Parser (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) #parseJSONList :: Value -> Parser [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)] #

class ToJSON a where #

A type that can be converted to JSON.

An example type and instance:

-- Allow ourselves to write Text literals.
{-# LANGUAGE OverloadedStrings #-}

data Coord = Coord { x :: Double, y :: Double }

instance ToJSON Coord where
toJSON (Coord x y) = object ["x" .= x, "y" .= y]

toEncoding (Coord x y) = pairs ("x" .= x <> "y" .= y)


Instead of manually writing your ToJSON instance, there are two options to do it automatically:

• Data.Aeson.TH provides Template Haskell functions which will derive an instance at compile time. The generated instance is optimized for your type so will probably be more efficient than the following two options:
• The compiler can provide a default generic implementation for toJSON.

To use the second, simply add a deriving Generic clause to your datatype and declare a ToJSON instance for your datatype without giving definitions for toJSON or toEncoding.

For example, the previous example can be simplified to a more minimal instance:

{-# LANGUAGE DeriveGeneric #-}

import GHC.Generics

data Coord = Coord { x :: Double, y :: Double } deriving Generic

instance ToJSON Coord where
toEncoding = genericToEncoding defaultOptions


Why do we provide an implementation for toEncoding here? The toEncoding function is a relatively new addition to this class. To allow users of older versions of this library to upgrade without having to edit all of their instances or encounter surprising incompatibilities, the default implementation of toEncoding uses toJSON. This produces correct results, but since it performs an intermediate conversion to a Value, it will be less efficient than directly emitting an Encoding. Our one-liner definition of toEncoding above bypasses the intermediate Value.

If DefaultSignatures doesn't give exactly the results you want, you can customize the generic encoding with only a tiny amount of effort, using genericToJSON and genericToEncoding with your preferred Options:

instance ToJSON Coord where
toJSON     = genericToJSON defaultOptions
toEncoding = genericToEncoding defaultOptions


Methods

toJSON :: a -> Value #

Convert a Haskell value to a JSON-friendly intermediate type.

Instances

 MethodstoJSON :: Bool -> Value #toJSONList :: [Bool] -> Value #toEncodingList :: [Bool] -> Encoding # MethodstoJSON :: Char -> Value #toJSONList :: [Char] -> Value #toEncodingList :: [Char] -> Encoding # MethodstoJSONList :: [Double] -> Value #toEncodingList :: [Double] -> Encoding # MethodstoJSONList :: [Float] -> Value #toEncodingList :: [Float] -> Encoding # MethodstoJSON :: Int -> Value #toJSONList :: [Int] -> Value #toEncodingList :: [Int] -> Encoding # MethodstoJSON :: Int8 -> Value #toJSONList :: [Int8] -> Value #toEncodingList :: [Int8] -> Encoding # MethodstoJSONList :: [Int16] -> Value #toEncodingList :: [Int16] -> Encoding # MethodstoJSONList :: [Int32] -> Value #toEncodingList :: [Int32] -> Encoding # MethodstoJSONList :: [Int64] -> Value #toEncodingList :: [Int64] -> Encoding # MethodstoJSONList :: [Integer] -> Value #toEncodingList :: [Integer] -> Encoding # MethodstoJSONList :: [Ordering] -> Value #toEncodingList :: [Ordering] -> Encoding # MethodstoJSON :: Word -> Value #toJSONList :: [Word] -> Value #toEncodingList :: [Word] -> Encoding # MethodstoJSONList :: [Word8] -> Value #toEncodingList :: [Word8] -> Encoding # MethodstoJSONList :: [Word16] -> Value #toEncodingList :: [Word16] -> Encoding # MethodstoJSONList :: [Word32] -> Value #toEncodingList :: [Word32] -> Encoding # MethodstoJSONList :: [Word64] -> Value #toEncodingList :: [Word64] -> Encoding # ToJSON () MethodstoJSON :: () -> Value #toEncoding :: () -> Encoding #toJSONList :: [()] -> Value #toEncodingList :: [()] -> Encoding # MethodstoJSONList :: [Scientific] -> Value # MethodstoJSONList :: [Number] -> Value #toEncodingList :: [Number] -> Encoding # MethodstoJSON :: Text -> Value #toJSONList :: [Text] -> Value #toEncodingList :: [Text] -> Encoding # MethodstoJSONList :: [UTCTime] -> Value #toEncodingList :: [UTCTime] -> Encoding # MethodstoJSONList :: [Value] -> Value #toEncodingList :: [Value] -> Encoding # MethodstoJSONList :: [DotNetTime] -> Value # MethodstoJSON :: Text -> Value #toJSONList :: [Text] -> Value #toEncodingList :: [Text] -> Encoding # MethodstoJSONList :: [Natural] -> Value #toEncodingList :: [Natural] -> Encoding # MethodstoJSONList :: [Version] -> Value #toEncodingList :: [Version] -> Encoding # MethodstoJSONList :: [IntSet] -> Value #toEncodingList :: [IntSet] -> Encoding # MethodstoJSONList :: [LocalTime] -> Value #toEncodingList :: [LocalTime] -> Encoding # MethodstoJSONList :: [ZonedTime] -> Value #toEncodingList :: [ZonedTime] -> Encoding # MethodstoJSONList :: [TimeOfDay] -> Value #toEncodingList :: [TimeOfDay] -> Encoding # MethodstoJSONList :: [NominalDiffTime] -> Value # MethodstoJSON :: Day -> Value #toJSONList :: [Day] -> Value #toEncodingList :: [Day] -> Encoding # ToJSON a => ToJSON [a] MethodstoJSON :: [a] -> Value #toEncoding :: [a] -> Encoding #toJSONList :: [[a]] -> Value #toEncodingList :: [[a]] -> Encoding # ToJSON a => ToJSON (Maybe a) MethodstoJSON :: Maybe a -> Value #toEncoding :: Maybe a -> Encoding #toJSONList :: [Maybe a] -> Value #toEncodingList :: [Maybe a] -> Encoding # (ToJSON a, Integral a) => ToJSON (Ratio a) MethodstoJSON :: Ratio a -> Value #toEncoding :: Ratio a -> Encoding #toJSONList :: [Ratio a] -> Value #toEncodingList :: [Ratio a] -> Encoding # ToJSON a => ToJSON (Identity a) MethodstoJSON :: Identity a -> Value #toJSONList :: [Identity a] -> Value #toEncodingList :: [Identity a] -> Encoding # ToJSON a => ToJSON (Min a) MethodstoJSON :: Min a -> Value #toEncoding :: Min a -> Encoding #toJSONList :: [Min a] -> Value #toEncodingList :: [Min a] -> Encoding # ToJSON a => ToJSON (Max a) MethodstoJSON :: Max a -> Value #toEncoding :: Max a -> Encoding #toJSONList :: [Max a] -> Value #toEncodingList :: [Max a] -> Encoding # ToJSON a => ToJSON (First a) MethodstoJSON :: First a -> Value #toEncoding :: First a -> Encoding #toJSONList :: [First a] -> Value #toEncodingList :: [First a] -> Encoding # ToJSON a => ToJSON (Last a) MethodstoJSON :: Last a -> Value #toEncoding :: Last a -> Encoding #toJSONList :: [Last a] -> Value #toEncodingList :: [Last a] -> Encoding # ToJSON a => ToJSON (WrappedMonoid a) MethodstoJSONList :: [WrappedMonoid a] -> Value #toEncodingList :: [WrappedMonoid a] -> Encoding # ToJSON a => ToJSON (Option a) MethodstoJSON :: Option a -> Value #toJSONList :: [Option a] -> Value #toEncodingList :: [Option a] -> Encoding # ToJSON a => ToJSON (NonEmpty a) MethodstoJSON :: NonEmpty a -> Value #toJSONList :: [NonEmpty a] -> Value #toEncodingList :: [NonEmpty a] -> Encoding # HasResolution a => ToJSON (Fixed a) MethodstoJSON :: Fixed a -> Value #toEncoding :: Fixed a -> Encoding #toJSONList :: [Fixed a] -> Value #toEncodingList :: [Fixed a] -> Encoding # ToJSON a => ToJSON (Dual a) MethodstoJSON :: Dual a -> Value #toEncoding :: Dual a -> Encoding #toJSONList :: [Dual a] -> Value #toEncodingList :: [Dual a] -> Encoding # ToJSON a => ToJSON (First a) MethodstoJSON :: First a -> Value #toEncoding :: First a -> Encoding #toJSONList :: [First a] -> Value #toEncodingList :: [First a] -> Encoding # ToJSON a => ToJSON (Last a) MethodstoJSON :: Last a -> Value #toEncoding :: Last a -> Encoding #toJSONList :: [Last a] -> Value #toEncodingList :: [Last a] -> Encoding # ToJSON a => ToJSON (IntMap a) MethodstoJSON :: IntMap a -> Value #toJSONList :: [IntMap a] -> Value #toEncodingList :: [IntMap a] -> Encoding # ToJSON v => ToJSON (Tree v) MethodstoJSON :: Tree v -> Value #toEncoding :: Tree v -> Encoding #toJSONList :: [Tree v] -> Value #toEncodingList :: [Tree v] -> Encoding # ToJSON a => ToJSON (Seq a) MethodstoJSON :: Seq a -> Value #toEncoding :: Seq a -> Encoding #toJSONList :: [Seq a] -> Value #toEncodingList :: [Seq a] -> Encoding # ToJSON a => ToJSON (Set a) MethodstoJSON :: Set a -> Value #toEncoding :: Set a -> Encoding #toJSONList :: [Set a] -> Value #toEncodingList :: [Set a] -> Encoding # ToJSON a => ToJSON (DList a) MethodstoJSON :: DList a -> Value #toEncoding :: DList a -> Encoding #toJSONList :: [DList a] -> Value #toEncodingList :: [DList a] -> Encoding # ToJSON a => ToJSON (Vector a) MethodstoJSON :: Vector a -> Value #toJSONList :: [Vector a] -> Value #toEncodingList :: [Vector a] -> Encoding # (Prim a, ToJSON a) => ToJSON (Vector a) MethodstoJSON :: Vector a -> Value #toJSONList :: [Vector a] -> Value #toEncodingList :: [Vector a] -> Encoding # (Storable a, ToJSON a) => ToJSON (Vector a) MethodstoJSON :: Vector a -> Value #toJSONList :: [Vector a] -> Value #toEncodingList :: [Vector a] -> Encoding # (Vector Vector a, ToJSON a) => ToJSON (Vector a) MethodstoJSON :: Vector a -> Value #toJSONList :: [Vector a] -> Value #toEncodingList :: [Vector a] -> Encoding # ToJSON a => ToJSON (HashSet a) MethodstoJSON :: HashSet a -> Value #toJSONList :: [HashSet a] -> Value #toEncodingList :: [HashSet a] -> Encoding # (ToJSON a, ToJSON b) => ToJSON (Either a b) MethodstoJSON :: Either a b -> Value #toEncoding :: Either a b -> Encoding #toJSONList :: [Either a b] -> Value #toEncodingList :: [Either a b] -> Encoding # (ToJSON a, ToJSON b) => ToJSON (a, b) MethodstoJSON :: (a, b) -> Value #toEncoding :: (a, b) -> Encoding #toJSONList :: [(a, b)] -> Value #toEncodingList :: [(a, b)] -> Encoding # (ToJSON v, ToJSONKey k) => ToJSON (HashMap k v) MethodstoJSON :: HashMap k v -> Value #toEncoding :: HashMap k v -> Encoding #toJSONList :: [HashMap k v] -> Value #toEncodingList :: [HashMap k v] -> Encoding # (ToJSON v, ToJSONKey k) => ToJSON (Map k v) MethodstoJSON :: Map k v -> Value #toEncoding :: Map k v -> Encoding #toJSONList :: [Map k v] -> Value #toEncodingList :: [Map k v] -> Encoding # ToJSON (Proxy k a) MethodstoJSON :: Proxy k a -> Value #toEncoding :: Proxy k a -> Encoding #toJSONList :: [Proxy k a] -> Value #toEncodingList :: [Proxy k a] -> Encoding # (ToJSON a, ToJSON b, ToJSON c) => ToJSON (a, b, c) MethodstoJSON :: (a, b, c) -> Value #toEncoding :: (a, b, c) -> Encoding #toJSONList :: [(a, b, c)] -> Value #toEncodingList :: [(a, b, c)] -> Encoding # ToJSON a => ToJSON (Const k a b) MethodstoJSON :: Const k a b -> Value #toEncoding :: Const k a b -> Encoding #toJSONList :: [Const k a b] -> Value #toEncodingList :: [Const k a b] -> Encoding # ToJSON b => ToJSON (Tagged k a b) MethodstoJSON :: Tagged k a b -> Value #toEncoding :: Tagged k a b -> Encoding #toJSONList :: [Tagged k a b] -> Value #toEncodingList :: [Tagged k a b] -> Encoding # (ToJSON a, ToJSON b, ToJSON c, ToJSON d) => ToJSON (a, b, c, d) MethodstoJSON :: (a, b, c, d) -> Value #toEncoding :: (a, b, c, d) -> Encoding #toJSONList :: [(a, b, c, d)] -> Value #toEncodingList :: [(a, b, c, d)] -> Encoding # (ToJSON1 f, ToJSON1 g, ToJSON a) => ToJSON (Sum * f g a) MethodstoJSON :: Sum * f g a -> Value #toEncoding :: Sum * f g a -> Encoding #toJSONList :: [Sum * f g a] -> Value #toEncodingList :: [Sum * f g a] -> Encoding # (ToJSON1 f, ToJSON1 g, ToJSON a) => ToJSON (Product * f g a) MethodstoJSON :: Product * f g a -> Value #toEncoding :: Product * f g a -> Encoding #toJSONList :: [Product * f g a] -> Value #toEncodingList :: [Product * f g a] -> Encoding # (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e) => ToJSON (a, b, c, d, e) MethodstoJSON :: (a, b, c, d, e) -> Value #toEncoding :: (a, b, c, d, e) -> Encoding #toJSONList :: [(a, b, c, d, e)] -> Value #toEncodingList :: [(a, b, c, d, e)] -> Encoding # (ToJSON1 f, ToJSON1 g, ToJSON a) => ToJSON (Compose * * f g a) MethodstoJSON :: Compose * * f g a -> Value #toEncoding :: Compose * * f g a -> Encoding #toJSONList :: [Compose * * f g a] -> Value #toEncodingList :: [Compose * * f g a] -> Encoding # (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f) => ToJSON (a, b, c, d, e, f) MethodstoJSON :: (a, b, c, d, e, f) -> Value #toEncoding :: (a, b, c, d, e, f) -> Encoding #toJSONList :: [(a, b, c, d, e, f)] -> Value #toEncodingList :: [(a, b, c, d, e, f)] -> Encoding # (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g) => ToJSON (a, b, c, d, e, f, g) MethodstoJSON :: (a, b, c, d, e, f, g) -> Value #toEncoding :: (a, b, c, d, e, f, g) -> Encoding #toJSONList :: [(a, b, c, d, e, f, g)] -> Value #toEncodingList :: [(a, b, c, d, e, f, g)] -> Encoding # (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h) => ToJSON (a, b, c, d, e, f, g, h) MethodstoJSON :: (a, b, c, d, e, f, g, h) -> Value #toEncoding :: (a, b, c, d, e, f, g, h) -> Encoding #toJSONList :: [(a, b, c, d, e, f, g, h)] -> Value #toEncodingList :: [(a, b, c, d, e, f, g, h)] -> Encoding # (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i) => ToJSON (a, b, c, d, e, f, g, h, i) MethodstoJSON :: (a, b, c, d, e, f, g, h, i) -> Value #toEncoding :: (a, b, c, d, e, f, g, h, i) -> Encoding #toJSONList :: [(a, b, c, d, e, f, g, h, i)] -> Value #toEncodingList :: [(a, b, c, d, e, f, g, h, i)] -> Encoding # (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j) => ToJSON (a, b, c, d, e, f, g, h, i, j) MethodstoJSON :: (a, b, c, d, e, f, g, h, i, j) -> Value #toEncoding :: (a, b, c, d, e, f, g, h, i, j) -> Encoding #toJSONList :: [(a, b, c, d, e, f, g, h, i, j)] -> Value #toEncodingList :: [(a, b, c, d, e, f, g, h, i, j)] -> Encoding # (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k) => ToJSON (a, b, c, d, e, f, g, h, i, j, k) MethodstoJSON :: (a, b, c, d, e, f, g, h, i, j, k) -> Value #toEncoding :: (a, b, c, d, e, f, g, h, i, j, k) -> Encoding #toJSONList :: [(a, b, c, d, e, f, g, h, i, j, k)] -> Value #toEncodingList :: [(a, b, c, d, e, f, g, h, i, j, k)] -> Encoding # (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l) MethodstoJSON :: (a, b, c, d, e, f, g, h, i, j, k, l) -> Value #toEncoding :: (a, b, c, d, e, f, g, h, i, j, k, l) -> Encoding #toJSONList :: [(a, b, c, d, e, f, g, h, i, j, k, l)] -> Value #toEncodingList :: [(a, b, c, d, e, f, g, h, i, j, k, l)] -> Encoding # (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l, m) MethodstoJSON :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Value #toEncoding :: (a, b, c, d, e, f, g, h, i, j, k, l, m) -> Encoding #toJSONList :: [(a, b, c, d, e, f, g, h, i, j, k, l, m)] -> Value #toEncodingList :: [(a, b, c, d, e, f, g, h, i, j, k, l, m)] -> Encoding # (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n) MethodstoJSON :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Value #toEncoding :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n) -> Encoding #toJSONList :: [(a, b, c, d, e, f, g, h, i, j, k, l, m, n)] -> Value #toEncodingList :: [(a, b, c, d, e, f, g, h, i, j, k, l, m, n)] -> Encoding # (ToJSON a, ToJSON b, ToJSON c, ToJSON d, ToJSON e, ToJSON f, ToJSON g, ToJSON h, ToJSON i, ToJSON j, ToJSON k, ToJSON l, ToJSON m, ToJSON n, ToJSON o) => ToJSON (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) MethodstoJSON :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Value #toEncoding :: (a, b, c, d, e, f, g, h, i, j, k, l, m, n, o) -> Encoding #toJSONList :: [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)] -> Value #toEncodingList :: [(a, b, c, d, e, f, g, h, i, j, k, l, m, n, o)] -> Encoding #

toJSON :: ToJSON a => a -> Value #

Convert a Haskell value to a JSON-friendly intermediate type.

data Value :: * #

A JSON value represented as a Haskell value.

Constructors

 Object ~Object

Instances

 Methods(==) :: Value -> Value -> Bool #(/=) :: Value -> Value -> Bool # Methodsgfoldl :: (forall d b. Data d => c (d -> b) -> d -> c b) -> (forall g. g -> c g) -> Value -> c Value #gunfold :: (forall b r. Data b => c (b -> r) -> c r) -> (forall r. r -> c r) -> Constr -> c Value #dataCast1 :: Typeable (* -> *) t => (forall d. Data d => c (t d)) -> Maybe (c Value) #dataCast2 :: Typeable (* -> * -> *) t => (forall d e. (Data d, Data e) => c (t d e)) -> Maybe (c Value) #gmapT :: (forall b. Data b => b -> b) -> Value -> Value #gmapQl :: (r -> r' -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r #gmapQr :: (r' -> r -> r) -> r -> (forall d. Data d => d -> r') -> Value -> r #gmapQ :: (forall d. Data d => d -> u) -> Value -> [u] #gmapQi :: Int -> (forall d. Data d => d -> u) -> Value -> u #gmapM :: Monad m => (forall d. Data d => d -> m d) -> Value -> m Value #gmapMp :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value #gmapMo :: MonadPlus m => (forall d. Data d => d -> m d) -> Value -> m Value # Methods MethodsshowsPrec :: Int -> Value -> ShowS #show :: Value -> String #showList :: [Value] -> ShowS # Methods Methodslift :: Value -> Q Exp # MethodshashWithSalt :: Int -> Value -> Int #hash :: Value -> Int # MethodstoJSONList :: [Value] -> Value #toEncodingList :: [Value] -> Encoding # Methods(.=) :: ToJSON v => Text -> v -> Pair # Methods Methodsrnf :: Value -> () #

object :: [Pair] -> Value #

Create a Value from a list of name/value Pairs. If duplicate keys arise, earlier keys and their associated values win.

(.=) :: KeyValue kv => forall v. ToJSON v => Text -> v -> kv #

(.:) :: FromJSON a => Object -> Text -> Parser a #

Retrieve the value associated with the given key of an Object. The result is empty if the key is not present or the value cannot be converted to the desired type.

This accessor is appropriate if the key and value must be present in an object for it to be valid. If the key and value are optional, use .:? instead.

Arguments

 :: Options Encoding options. -> Name Name of the type for which to generate ToJSON and FromJSON instances. -> Q [Dec]

Generates both ToJSON and FromJSON instance declarations for the given data type or data family instance constructor.

This is a convienience function which is equivalent to calling both deriveToJSON and deriveFromJSON.

Default encoding Options:

Options
{ fieldLabelModifier      = id
, constructorTagModifier  = id
, allNullaryToStringTag   = True
, omitNothingFields       = False
, sumEncoding             = defaultTaggedObject
, unwrapUnaryRecords      = False
}


Function applied to field labels. Handy for removing common record prefixes for example.

Function applied to constructor tags which could be handy for lower-casing them for example.